-- ============================================================
-- V019: LLM 운영 페이지 권한 트리 항목 추가
-- PR #22에서 추가된 /llm-ops 페이지에 대응하는 권한 리소스
-- ============================================================

INSERT INTO kcg.auth_perm_tree(rsrc_cd, parent_cd, rsrc_nm, rsrc_level, sort_ord)
VALUES ('ai-operations:llm-ops', 'ai-operations', 'LLM 운영', 1, 35)
ON CONFLICT (rsrc_cd) DO NOTHING;

-- ADMIN 역할에 자동 부여
INSERT INTO kcg.auth_perm(role_sn, rsrc_cd, oper_cd, grant_yn)
SELECT r.role_sn, 'ai-operations:llm-ops', op.oper_cd, 'Y'
FROM kcg.auth_role r
CROSS JOIN (VALUES ('READ'), ('CREATE'), ('UPDATE'), ('DELETE'), ('EXPORT')) AS op(oper_cd)
WHERE r.role_cd = 'ADMIN'
ON CONFLICT (role_sn, rsrc_cd, oper_cd) DO NOTHING;
