-- V83: WITHDRAW_REQUESTS 메뉴에 EXECUTE 권한 추가
-- P6 펌뱅킹 재시도 endpoint(POST /api/internal/bank-retry) 가 EXECUTE 권한을 요구.
-- 동일 패턴 V72/V73 참조.

-- 1. menu_permission에 EXECUTE 추가 (이미 있으면 skip)
INSERT INTO menu_permission (menu_id, perm_code, perm_name, sort_order)
SELECT m.menu_id, 'EXECUTE', '실행', 70
  FROM menu m
 WHERE m.menu_code = 'WITHDRAW_REQUESTS'
   AND NOT EXISTS (
       SELECT 1 FROM menu_permission mp2
        WHERE mp2.menu_id = m.menu_id AND mp2.perm_code = 'EXECUTE'
   );

-- 2. SUPER_ADMIN / ADMIN 에 EXECUTE 권한 부여
INSERT INTO role_menu_permission (role_id, menu_id, perm_code, is_granted)
SELECT r.role_id, mp.menu_id, mp.perm_code, 'Y'
  FROM role r
  CROSS JOIN menu_permission mp
  JOIN menu m ON m.menu_id = mp.menu_id
 WHERE r.role_code IN ('SUPER_ADMIN', 'ADMIN')
   AND mp.perm_code = 'EXECUTE'
   AND m.menu_code = 'WITHDRAW_REQUESTS'
   AND NOT EXISTS (
       SELECT 1 FROM role_menu_permission rmp2
        WHERE rmp2.role_id   = r.role_id
          AND rmp2.menu_id   = mp.menu_id
          AND rmp2.perm_code = 'EXECUTE'
   );
