-- aerial:spectral (AI 탐지/분석) 서브탭 권한 추가
-- 기존 aerial 서브탭(satellite) 뒤, cctv 앞에 배치 (SORT_ORD = 6)

-- 기존 cctv, theory 순서 밀기
UPDATE AUTH_PERM_TREE SET SORT_ORD = 7 WHERE RSRC_CD = 'aerial:cctv';
UPDATE AUTH_PERM_TREE SET SORT_ORD = 8 WHERE RSRC_CD = 'aerial:theory';

-- spectral 리소스 추가
INSERT INTO AUTH_PERM_TREE (RSRC_CD, PARENT_CD, RSRC_NM, RSRC_LEVEL, SORT_ORD)
VALUES ('aerial:spectral', 'aerial', 'AI 탐지/분석', 1, 6)
ON CONFLICT (RSRC_CD) DO NOTHING;

-- 기존 역할에 spectral READ 권한 부여 (aerial READ 권한이 있는 역할)
INSERT INTO AUTH_PERM (ROLE_SN, RSRC_CD, OPER_CD, USE_YN)
SELECT ap.ROLE_SN, 'aerial:spectral', ap.OPER_CD, ap.USE_YN
FROM AUTH_PERM ap
WHERE ap.RSRC_CD = 'aerial'
  AND ap.USE_YN = 'Y'
ON CONFLICT (ROLE_SN, RSRC_CD, OPER_CD) DO NOTHING;
