-- 将 Prompt配置 菜单挂载到：开发专用 -> Prompt配置
-- 执行后请在“角色授权”里给对应角色勾选新菜单。

SET @dev_parent_id := (
  SELECT id
  FROM sys_resource
  WHERE name = '开发专用' AND level = 1
  ORDER BY id
  LIMIT 1
);

INSERT INTO sys_resource(code, name, resource_id, level, sort, status)
SELECT 'ai/prompt_config.html', 'Prompt配置', @dev_parent_id, 2, 1000, 1
FROM dual
WHERE @dev_parent_id IS NOT NULL
  AND NOT EXISTS (
    SELECT 1
    FROM sys_resource
    WHERE code = 'ai/prompt_config.html' AND level = 2
  );

SET @ai_prompt_id := (
  SELECT id
  FROM sys_resource
  WHERE code = 'ai/prompt_config.html' AND level = 2
  ORDER BY id
  LIMIT 1
);

INSERT INTO sys_resource(code, name, resource_id, level, sort, status)
SELECT 'ai/prompt_config.html#view', '查看', @ai_prompt_id, 3, 1, 1
FROM dual
WHERE @ai_prompt_id IS NOT NULL
  AND NOT EXISTS (
    SELECT 1
    FROM sys_resource
    WHERE code = 'ai/prompt_config.html#view' AND level = 3
  );

SELECT id, code, name, resource_id, level, sort, status
FROM sys_resource
WHERE code IN ('ai/prompt_config.html', 'ai/prompt_config.html#view');
