-- 植物养护后台管理系统 - 菜单初始化数据
-- 执行前请确保 menus 表已存在

-- 清空现有菜单数据（可选，谨慎使用）
-- DELETE FROM menus;

-- 生成UUID函数（如果数据库不支持，可以手动指定ID）
-- MySQL可以使用 UUID() 函数

-- ============================================
-- 一级菜单
-- ============================================

-- 仪表盘
INSERT INTO menus (id, parent_id, category, name, title, code, permission, locale, icon, sort, created_at, updated_at) VALUES
('menu_dashboard', '0', 1, 'dashboard', '仪表盘', '/dashboard', '', 'menu.dashboard', 'dashboard', 1, NOW(), NOW());

-- 系统管理
INSERT INTO menus (id, parent_id, category, name, title, code, permission, locale, icon, sort, created_at, updated_at) VALUES
('menu_system', '0', 1, 'system', '系统管理', '/system', '', 'menu.system', 'settings', 2, NOW(), NOW());

-- 社区管理
INSERT INTO menus (id, parent_id, category, name, title, code, permission, locale, icon, sort, created_at, updated_at) VALUES
('menu_community', '0', 1, 'community', '社区管理', '/community', '', 'menu.community', 'message', 3, NOW(), NOW());

-- 百科管理
INSERT INTO menus (id, parent_id, category, name, title, code, permission, locale, icon, sort, created_at, updated_at) VALUES
('menu_wiki', '0', 1, 'wiki', '百科管理', '/wiki', '', 'menu.wiki', 'book', 4, NOW(), NOW());

-- ============================================
-- 系统管理 - 子菜单
-- ============================================

-- 用户管理
INSERT INTO menus (id, parent_id, category, name, title, code, permission, locale, icon, sort, created_at, updated_at) VALUES
('menu_system_user', 'menu_system', 1, 'user', '用户管理', '/system/users', 'user:list', 'menu.system.user', 'users', 1, NOW(), NOW());

-- 角色管理
INSERT INTO menus (id, parent_id, category, name, title, code, permission, locale, icon, sort, created_at, updated_at) VALUES
('menu_system_role', 'menu_system', 1, 'role', '角色管理', '/system/roles', 'role:list', 'menu.system.role', 'shield', 2, NOW(), NOW());

-- 菜单管理
INSERT INTO menus (id, parent_id, category, name, title, code, permission, locale, icon, sort, created_at, updated_at) VALUES
('menu_system_menu', 'menu_system', 1, 'menu', '菜单管理', '/system/menus', 'menu:list', 'menu.system.menu', 'menu', 3, NOW(), NOW());

-- 客户端管理
INSERT INTO menus (id, parent_id, category, name, title, code, permission, locale, icon, sort, created_at, updated_at) VALUES
('menu_system_client', 'menu_system', 1, 'client', '客户端管理', '/system/clients', 'client:list', 'menu.system.client', 'monitor', 4, NOW(), NOW());

-- 文件管理
INSERT INTO menus (id, parent_id, category, name, title, code, permission, locale, icon, sort, created_at, updated_at) VALUES
('menu_system_file', 'menu_system', 1, 'file', '文件管理', '/system/files', 'file:list', 'menu.system.file', 'folder', 5, NOW(), NOW());

-- ============================================
-- 社区管理 - 子菜单
-- ============================================

-- 话题管理
INSERT INTO menus (id, parent_id, category, name, title, code, permission, locale, icon, sort, created_at, updated_at) VALUES
('menu_community_topic', 'menu_community', 1, 'topic', '话题管理', '/topics', 'topic:list', 'menu.community.topic', 'hash', 1, NOW(), NOW());

-- 帖子管理
INSERT INTO menus (id, parent_id, category, name, title, code, permission, locale, icon, sort, created_at, updated_at) VALUES
('menu_community_post', 'menu_community', 1, 'post', '帖子管理', '/posts', 'post:list', 'menu.community.post', 'file-text', 2, NOW(), NOW());

-- ============================================
-- 百科管理 - 子菜单
-- ============================================

-- 分类管理
INSERT INTO menus (id, parent_id, category, name, title, code, permission, locale, icon, sort, created_at, updated_at) VALUES
('menu_wiki_class', 'menu_wiki', 1, 'wikiClass', '分类管理', '/categories', 'wikiClass:list', 'menu.wiki.class', 'folder-tree', 1, NOW(), NOW());

-- 植物百科
INSERT INTO menus (id, parent_id, category, name, title, code, permission, locale, icon, sort, created_at, updated_at) VALUES
('menu_wiki_plant', 'menu_wiki', 1, 'plant', '植物百科', '/plants', 'wiki:list', 'menu.wiki.plant', 'leaf', 2, NOW(), NOW());

-- ============================================
-- 按钮权限（category = 2 表示按钮）
-- ============================================

-- 用户管理按钮
INSERT INTO menus (id, parent_id, category, name, title, code, permission, locale, icon, sort, created_at, updated_at) VALUES
('btn_user_add', 'menu_system_user', 2, 'userAdd', '新增用户', '', 'user:add', '', '', 1, NOW(), NOW()),
('btn_user_edit', 'menu_system_user', 2, 'userEdit', '编辑用户', '', 'user:edit', '', '', 2, NOW(), NOW()),
('btn_user_delete', 'menu_system_user', 2, 'userDelete', '删除用户', '', 'user:delete', '', '', 3, NOW(), NOW()),
('btn_user_grant', 'menu_system_user', 2, 'userGrant', '分配角色', '', 'user:grant', '', '', 4, NOW(), NOW());

-- 角色管理按钮
INSERT INTO menus (id, parent_id, category, name, title, code, permission, locale, icon, sort, created_at, updated_at) VALUES
('btn_role_add', 'menu_system_role', 2, 'roleAdd', '新增角色', '', 'role:add', '', '', 1, NOW(), NOW()),
('btn_role_edit', 'menu_system_role', 2, 'roleEdit', '编辑角色', '', 'role:edit', '', '', 2, NOW(), NOW()),
('btn_role_delete', 'menu_system_role', 2, 'roleDelete', '删除角色', '', 'role:delete', '', '', 3, NOW(), NOW()),
('btn_role_grant', 'menu_system_role', 2, 'roleGrant', '授权菜单', '', 'role:grant', '', '', 4, NOW(), NOW());

-- 菜单管理按钮
INSERT INTO menus (id, parent_id, category, name, title, code, permission, locale, icon, sort, created_at, updated_at) VALUES
('btn_menu_add', 'menu_system_menu', 2, 'menuAdd', '新增菜单', '', 'menu:add', '', '', 1, NOW(), NOW()),
('btn_menu_edit', 'menu_system_menu', 2, 'menuEdit', '编辑菜单', '', 'menu:edit', '', '', 2, NOW(), NOW()),
('btn_menu_delete', 'menu_system_menu', 2, 'menuDelete', '删除菜单', '', 'menu:delete', '', '', 3, NOW(), NOW());

-- 话题管理按钮
INSERT INTO menus (id, parent_id, category, name, title, code, permission, locale, icon, sort, created_at, updated_at) VALUES
('btn_topic_add', 'menu_community_topic', 2, 'topicAdd', '新增话题', '', 'topic:add', '', '', 1, NOW(), NOW()),
('btn_topic_edit', 'menu_community_topic', 2, 'topicEdit', '编辑话题', '', 'topic:edit', '', '', 2, NOW(), NOW()),
('btn_topic_delete', 'menu_community_topic', 2, 'topicDelete', '删除话题', '', 'topic:delete', '', '', 3, NOW(), NOW());

-- 帖子管理按钮
INSERT INTO menus (id, parent_id, category, name, title, code, permission, locale, icon, sort, created_at, updated_at) VALUES
('btn_post_review', 'menu_community_post', 2, 'postReview', '审核帖子', '', 'post:review', '', '', 1, NOW(), NOW()),
('btn_post_delete', 'menu_community_post', 2, 'postDelete', '删除帖子', '', 'post:delete', '', '', 2, NOW(), NOW());

-- 分类管理按钮
INSERT INTO menus (id, parent_id, category, name, title, code, permission, locale, icon, sort, created_at, updated_at) VALUES
('btn_class_add', 'menu_wiki_class', 2, 'classAdd', '新增分类', '', 'wikiClass:add', '', '', 1, NOW(), NOW()),
('btn_class_edit', 'menu_wiki_class', 2, 'classEdit', '编辑分类', '', 'wikiClass:edit', '', '', 2, NOW(), NOW()),
('btn_class_delete', 'menu_wiki_class', 2, 'classDelete', '删除分类', '', 'wikiClass:delete', '', '', 3, NOW(), NOW());

-- 植物百科按钮
INSERT INTO menus (id, parent_id, category, name, title, code, permission, locale, icon, sort, created_at, updated_at) VALUES
('btn_wiki_add', 'menu_wiki_plant', 2, 'wikiAdd', '新增百科', '', 'wiki:add', '', '', 1, NOW(), NOW()),
('btn_wiki_edit', 'menu_wiki_plant', 2, 'wikiEdit', '编辑百科', '', 'wiki:edit', '', '', 2, NOW(), NOW()),
('btn_wiki_delete', 'menu_wiki_plant', 2, 'wikiDelete', '删除百科', '', 'wiki:delete', '', '', 3, NOW(), NOW());

-- 文件管理按钮
INSERT INTO menus (id, parent_id, category, name, title, code, permission, locale, icon, sort, created_at, updated_at) VALUES
('btn_file_upload', 'menu_system_file', 2, 'fileUpload', '上传文件', '', 'file:upload', '', '', 1, NOW(), NOW()),
('btn_file_delete', 'menu_system_file', 2, 'fileDelete', '删除文件', '', 'file:delete', '', '', 2, NOW(), NOW());

-- ============================================
-- 查询验证
-- ============================================
-- SELECT * FROM menus WHERE parent_id = '0' ORDER BY sort;
-- SELECT * FROM menus WHERE parent_id = 'menu_system' ORDER BY sort;
