-- =====================================================
-- 龙虾引擎 (Lobster Workflow Engine) 菜单初始化
-- 将前端静态路由 /lobster/* 的 12 个子页面录入 sys_menu
-- 租户管理员可通过角色权限控制访问
--
-- 【重要】租户菜单的三层体系：
--   ┌─────────────────────────────────────────────────────┐
--   │ 管理员数据库(ylrz_saas)                                │
--   │   ├── fs_menu         ← adminUI 总后台自己的菜单       │
--   │   │    (admin_menu_init.sql, add_missing_admin_menu.sql) │
--   │   └── tenant_sys_menu ← 新租户菜单模板（创建时复制）    │
--   └─────────────────────────────────────────────────────┘
--   ┌─────────────────────────────────────────────────────┐
--   │ 租户数据库(tenant_xxx)                                │
--   │   └── sys_menu        ← 租户实际看到的动态菜单        │
--   │   来源：                                              │
--   │     • 新租户：TenantUtils.initMenus() 从 tenant_sys_menu 复制 │
--   │     • 已有租户：TenantUpgradeService 执行 V*__*.sql 迁移脚本  │
--   └─────────────────────────────────────────────────────┘
--
-- 用法：
--   1. 已有租户：直接在各租户库执行本脚本，或通过迁移脚本自动应用
--      （推荐使用迁移脚本：fs-admin-saas/.../V20260521_01__add_lobster_engine_menus.sql）
--   2. 新租户：需确保 tenant_sys_menu 模板表也包含这些条目
--      迁移脚本末尾已包含 INSERT INTO tenant_sys_menu 同步逻辑
-- =====================================================

-- 1. 根菜单：龙虾引擎 (parent_id=0 作为顶层菜单)
INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, menu_type, icon, visible, status, is_frame, is_cache, create_by, create_time, remark)
VALUES (29900, '龙虾引擎', 0, 100, '/lobster', '', 'M', 'el-icon-cpu', '0', '0', 0, 0, 'admin', NOW(), 'Lobster Workflow Engine顶层菜单');

-- 2. AI生产工作流 目录（包含画布和模板库两个子页）
INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, menu_type, icon, visible, status, is_frame, is_cache, create_by, create_time, remark)
VALUES (29901, 'AI生产工作流', 29900, 1, 'production-workflow', '', 'M', 'el-icon-component', '0', '0', 0, 0, 'admin', NOW(), NULL);

-- 2a. 工作流画布
INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, menu_type, icon, visible, status, is_frame, is_cache, create_by, create_time, remark)
VALUES (29902, '工作流画布', 29901, 1, 'canvas', 'lobster/workflow-canvas/index', 'C', 'el-icon-chart', '0', '0', 0, 0, 'admin', NOW(), NULL);

-- 2b. 工作流模板库
INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, menu_type, icon, visible, status, is_frame, is_cache, create_by, create_time, remark)
VALUES (29903, '工作流模板库', 29901, 2, 'template', 'lobster/template/index', 'C', 'el-icon-documentation', '0', '0', 0, 0, 'admin', NOW(), NULL);

-- 3. AI生成工作流
INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, menu_type, icon, visible, status, is_frame, is_cache, create_by, create_time, remark)
VALUES (29904, 'AI生成工作流', 29900, 2, 'workflow-generate', 'lobster/workflow-generate/index', 'C', 'el-icon-build', '0', '0', 0, 0, 'admin', NOW(), NULL);

-- 4. 实例监控
INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, menu_type, icon, visible, status, is_frame, is_cache, create_by, create_time, remark)
VALUES (29905, '实例监控', 29900, 3, 'instance', 'lobster/instance/index', 'C', 'el-icon-monitor', '0', '0', 0, 0, 'admin', NOW(), NULL);

-- 5. AI优化建议
INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, menu_type, icon, visible, status, is_frame, is_cache, create_by, create_time, remark)
VALUES (29906, 'AI优化建议', 29900, 4, 'optimization', 'lobster/optimization/index', 'C', 'el-icon-eye-open', '0', '0', 0, 0, 'admin', NOW(), NULL);

-- 6. 提示词管理
INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, menu_type, icon, visible, status, is_frame, is_cache, create_by, create_time, remark)
VALUES (29907, '提示词管理', 29900, 5, 'prompt', 'lobster/prompt/index', 'C', 'el-icon-edit', '0', '0', 0, 0, 'admin', NOW(), NULL);

-- 7. 销冠语料学习
INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, menu_type, icon, visible, status, is_frame, is_cache, create_by, create_time, remark)
VALUES (29908, '销冠语料学习', 29900, 6, 'sales-corpus', 'lobster/sales-corpus/index', 'C', 'el-icon-star', '0', '0', 0, 0, 'admin', NOW(), NULL);

-- 8. 接口注册中心
INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, menu_type, icon, visible, status, is_frame, is_cache, create_by, create_time, remark)
VALUES (29909, '接口注册中心', 29900, 7, 'api-registry', 'lobster/api-registry/index', 'C', 'el-icon-nested', '0', '0', 0, 0, 'admin', NOW(), NULL);

-- 9. 死信队列
INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, menu_type, icon, visible, status, is_frame, is_cache, create_by, create_time, remark)
VALUES (29910, '死信队列', 29900, 8, 'dead-letter', 'lobster/dead-letter/index', 'C', 'el-icon-bug', '0', '0', 0, 0, 'admin', NOW(), NULL);

-- 10. 节点审核
INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, menu_type, icon, visible, status, is_frame, is_cache, create_by, create_time, remark)
VALUES (29911, '节点审核', 29900, 9, 'event-audit', 'lobster/event-audit/index', 'C', 'el-icon-checkbox', '0', '0', 0, 0, 'admin', NOW(), NULL);

-- 11. 聚合聊天
INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, menu_type, icon, visible, status, is_frame, is_cache, create_by, create_time, remark)
VALUES (29912, '聚合聊天', 29900, 10, 'chat-aggregate', 'lobster/chat-aggregate/index', 'C', 'el-icon-message', '0', '0', 0, 0, 'admin', NOW(), NULL);

-- 12. 模型配置
INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, menu_type, icon, visible, status, is_frame, is_cache, create_by, create_time, remark)
VALUES (29913, '模型配置', 29900, 11, 'model-config', 'lobster/model-config/index', 'C', 'el-icon-server', '0', '0', 0, 0, 'admin', NOW(), NULL);

-- 13. Token系数管理
INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, menu_type, icon, visible, status, is_frame, is_cache, create_by, create_time, remark)
VALUES (29914, 'Token系数管理', 29900, 12, 'billing', 'lobster/billing/index', 'C', 'el-icon-money', '0', '0', 0, 0, 'admin', NOW(), NULL);

-- =====================================================
-- 将龙虾引擎菜单授权给租户默认角色（根据实际role_id调整）
-- 假设租户端管理员角色role_key='tenant_admin'，请先查询role_id
-- SELECT role_id FROM sys_role WHERE role_key = 'tenant_admin';
-- 然后将下面的 1 替换为实际role_id
-- =====================================================
-- INSERT INTO sys_role_menu (role_id, menu_id)
-- SELECT 1, menu_id FROM sys_menu WHERE menu_id BETWEEN 29900 AND 29914;
