-- ================================================================
-- Sundynix RBAC 基础数据初始化脚本
-- 数据库: sundynix_micro_go
-- 执行前请确保表已通过 AutoMigrate 自动创建
-- ================================================================

USE sundynix_micro_go;

-- ================================================================
-- 1. 客户端 (sundynix_client)
-- ================================================================
INSERT INTO sundynix_client (id, client_id, name, grant_type, additional_info, active_timeout, created_at, updated_at) VALUES
('cd67bf8d-81dc-404a-8dc8-4beaf9091cc8', 'sundynix-pc',   'PC管理后台',   'password',    '{"platform":"web"}',  86400,   NOW(), NOW()),
('8fa30b91-850c-42a8-9951-3d3ebe9c9a0d', 'sundynix-mini', '微信小程序端', 'wechat_mini', '{"platform":"mini"}', 604800,  NOW(), NOW()),
('bae0f342-0778-4d80-90fc-08837a7e5c50', 'sundynix-app',  '移动APP端',    'password',    '{"platform":"app"}',  2592000, NOW(), NOW());

-- ================================================================
-- 2. 角色 (sundynix_role)
-- ================================================================
INSERT INTO sundynix_role (id, name, code, sort, created_at, updated_at) VALUES
('091881d9-10d8-4c01-aa20-22c3988e2a2a', '超级管理员', 'admin',  1, NOW(), NOW()),
('2cfa0b60-d09e-4b14-8238-962feed60a0c', '普通用户',   'user',   2, NOW(), NOW()),
('23f0622e-baf7-4733-9447-733dbea1fae4', '运维人员',   'editor', 3, NOW(), NOW());

-- ================================================================
-- 3. 菜单 (sundynix_menu)
--    category: 1=菜单  2=按钮/权限
-- ================================================================

-- -------- 一级菜单 --------
INSERT INTO sundynix_menu (id, parent_id, category, name, title, code, path, permission, locale, icon, sort, created_at, updated_at) VALUES
('41c44269-4dbb-404a-bcd4-bc5734dfa1f5', '0', 1, 'Dashboard',  '仪表盘',   'dashboard',  '/dashboard',  '', 'menu.dashboard', 'IconDashboard', 1, NOW(), NOW()),
('8bc27535-ca46-4d09-8c43-a8a058883552', '0', 1, 'System',     '系统管理', 'system',     '/system',     '', 'menu.system',    'IconSettings',  2, NOW(), NOW()),
('f719df64-7927-481e-b178-48052bf93104', '0', 1, 'UserCenter', '用户中心', 'userCenter', '/user',       '', 'menu.user',      'IconUser',      3, NOW(), NOW()),
('11d945a2-5c05-422f-9608-3b293eabc90f', '0', 1, 'Plant',      '植物服务', 'plant',      '/plant',      '', 'menu.plant',     'IconLeaf',      4, NOW(), NOW());

-- -------- System 子菜单 --------
INSERT INTO sundynix_menu (id, parent_id, category, name, title, code, path, permission, locale, icon, sort, created_at, updated_at) VALUES
('b94c6c49-3224-4bf3-8c19-8a0435579198', '8bc27535-ca46-4d09-8c43-a8a058883552', 1, 'RoleManage',   '角色管理',   'systemRole',   '/system/role',   '', 'menu.system.role',   'IconUserGroup', 1, NOW(), NOW()),
('8768117d-3542-4adc-ba05-b506901a07c1', '8bc27535-ca46-4d09-8c43-a8a058883552', 1, 'MenuManage',   '菜单管理',   'systemMenu',   '/system/menu',   '', 'menu.system.menu',   'IconMenu',      2, NOW(), NOW()),
('e2e51e57-2a49-4480-95f3-1b3d4e97c2af', '8bc27535-ca46-4d09-8c43-a8a058883552', 1, 'DictManage',   '字典管理',   'systemDict',   '/system/dict',   '', 'menu.system.dict',   'IconBook',      3, NOW(), NOW()),
('72c2cd9c-c794-484a-8aab-7c2bccdbcc83', '8bc27535-ca46-4d09-8c43-a8a058883552', 1, 'ClientManage', '客户端管理', 'systemClient', '/system/client', '', 'menu.system.client', 'IconDesktop',   4, NOW(), NOW()),
('78722dc5-0632-4560-a99d-9d1abbc3cec9', '8bc27535-ca46-4d09-8c43-a8a058883552', 1, 'LogManage',    '操作日志',   'systemLog',    '/system/log',    '', 'menu.system.log',    'IconFile',      5, NOW(), NOW());

-- -------- UserCenter 子菜单 --------
INSERT INTO sundynix_menu (id, parent_id, category, name, title, code, path, permission, locale, icon, sort, created_at, updated_at) VALUES
('fdd5dc3f-22c1-4226-b534-e527c3d713ed', 'f719df64-7927-481e-b178-48052bf93104', 1, 'UserList',    '用户列表', 'userList',    '/user/list',    '', 'menu.user.list',    'IconList',   1, NOW(), NOW()),
('038fdb2c-f21f-4540-b822-c0b9037eaec7', 'f719df64-7927-481e-b178-48052bf93104', 1, 'UserProfile', '个人中心', 'userProfile', '/user/profile', '', 'menu.user.profile', 'IconIdcard', 2, NOW(), NOW());

-- -------- 按钮级权限 (category=2) --------
INSERT INTO sundynix_menu (id, parent_id, category, name, title, code, path, permission, locale, icon, sort, created_at, updated_at) VALUES
('d9c19b2a-1b51-4f37-ba3e-4a12259a9918', 'b94c6c49-3224-4bf3-8c19-8a0435579198', 2, 'RoleAdd',    '新增角色', 'roleAdd',    '', 'sys:role:add',    '', '', 1, NOW(), NOW()),
('cc837307-21ec-4a8d-a562-3bb0f4a43c27', 'b94c6c49-3224-4bf3-8c19-8a0435579198', 2, 'RoleEdit',   '编辑角色', 'roleEdit',   '', 'sys:role:edit',   '', '', 2, NOW(), NOW()),
('80873067-fa1c-4ea2-bc02-20979eab4363', 'b94c6c49-3224-4bf3-8c19-8a0435579198', 2, 'RoleDelete', '删除角色', 'roleDelete', '', 'sys:role:delete', '', '', 3, NOW(), NOW()),
('98f56888-8861-4b01-9db4-2461f5a4ea3b', 'fdd5dc3f-22c1-4226-b534-e527c3d713ed', 2, 'UserAdd',    '新增用户', 'userAdd',    '', 'sys:user:add',    '', '', 1, NOW(), NOW()),
('d1d313d0-a51a-4c45-a89b-e31c68eaf3d9', 'fdd5dc3f-22c1-4226-b534-e527c3d713ed', 2, 'UserEdit',   '编辑用户', 'userEdit',   '', 'sys:user:edit',   '', '', 2, NOW(), NOW()),
('1114c4ac-7da9-4e03-a314-482ac669337e', 'fdd5dc3f-22c1-4226-b534-e527c3d713ed', 2, 'UserDelete', '删除用户', 'userDelete', '', 'sys:user:delete', '', '', 3, NOW(), NOW());

-- ================================================================
-- 4. 角色-菜单关联 (sundynix_role_menu)
-- ================================================================

-- admin 拥有所有菜单
INSERT INTO sundynix_role_menu (role_id, menu_id) VALUES
('091881d9-10d8-4c01-aa20-22c3988e2a2a', '41c44269-4dbb-404a-bcd4-bc5734dfa1f5'),
('091881d9-10d8-4c01-aa20-22c3988e2a2a', '8bc27535-ca46-4d09-8c43-a8a058883552'),
('091881d9-10d8-4c01-aa20-22c3988e2a2a', 'f719df64-7927-481e-b178-48052bf93104'),
('091881d9-10d8-4c01-aa20-22c3988e2a2a', '11d945a2-5c05-422f-9608-3b293eabc90f'),
('091881d9-10d8-4c01-aa20-22c3988e2a2a', 'b94c6c49-3224-4bf3-8c19-8a0435579198'),
('091881d9-10d8-4c01-aa20-22c3988e2a2a', '8768117d-3542-4adc-ba05-b506901a07c1'),
('091881d9-10d8-4c01-aa20-22c3988e2a2a', 'e2e51e57-2a49-4480-95f3-1b3d4e97c2af'),
('091881d9-10d8-4c01-aa20-22c3988e2a2a', '72c2cd9c-c794-484a-8aab-7c2bccdbcc83'),
('091881d9-10d8-4c01-aa20-22c3988e2a2a', '78722dc5-0632-4560-a99d-9d1abbc3cec9'),
('091881d9-10d8-4c01-aa20-22c3988e2a2a', 'fdd5dc3f-22c1-4226-b534-e527c3d713ed'),
('091881d9-10d8-4c01-aa20-22c3988e2a2a', '038fdb2c-f21f-4540-b822-c0b9037eaec7'),
('091881d9-10d8-4c01-aa20-22c3988e2a2a', 'd9c19b2a-1b51-4f37-ba3e-4a12259a9918'),
('091881d9-10d8-4c01-aa20-22c3988e2a2a', 'cc837307-21ec-4a8d-a562-3bb0f4a43c27'),
('091881d9-10d8-4c01-aa20-22c3988e2a2a', '80873067-fa1c-4ea2-bc02-20979eab4363'),
('091881d9-10d8-4c01-aa20-22c3988e2a2a', '98f56888-8861-4b01-9db4-2461f5a4ea3b'),
('091881d9-10d8-4c01-aa20-22c3988e2a2a', 'd1d313d0-a51a-4c45-a89b-e31c68eaf3d9'),
('091881d9-10d8-4c01-aa20-22c3988e2a2a', '1114c4ac-7da9-4e03-a314-482ac669337e');

-- user 只有 Dashboard + 个人中心
INSERT INTO sundynix_role_menu (role_id, menu_id) VALUES
('2cfa0b60-d09e-4b14-8238-962feed60a0c', '41c44269-4dbb-404a-bcd4-bc5734dfa1f5'),
('2cfa0b60-d09e-4b14-8238-962feed60a0c', 'f719df64-7927-481e-b178-48052bf93104'),
('2cfa0b60-d09e-4b14-8238-962feed60a0c', '038fdb2c-f21f-4540-b822-c0b9037eaec7');

-- editor 有 Dashboard + 用户中心(只读) + 植物服务
INSERT INTO sundynix_role_menu (role_id, menu_id) VALUES
('23f0622e-baf7-4733-9447-733dbea1fae4', '41c44269-4dbb-404a-bcd4-bc5734dfa1f5'),
('23f0622e-baf7-4733-9447-733dbea1fae4', 'f719df64-7927-481e-b178-48052bf93104'),
('23f0622e-baf7-4733-9447-733dbea1fae4', '11d945a2-5c05-422f-9608-3b293eabc90f'),
('23f0622e-baf7-4733-9447-733dbea1fae4', 'fdd5dc3f-22c1-4226-b534-e527c3d713ed'),
('23f0622e-baf7-4733-9447-733dbea1fae4', '038fdb2c-f21f-4540-b822-c0b9037eaec7');

-- ================================================================
-- 5. 用户 (sundynix_user)
-- ================================================================
INSERT INTO sundynix_user (id, tenant_id, client_id, name, account, password, nick_name, phone, gender, created_at, updated_at) VALUES
('b47eae1d-59e5-4cc5-a088-9aaaaba4dddd', '1', 'sundynix-pc', '超级管理员', 'sundynix', '$2a$10$YRTuwceTYOa10c3R5mMBB.8fHKOFL6DO1OprwSFjnc20R.qDv3PTq', 'Admin',  '13800000000', 0, NOW(), NOW()),
('11abce94-082c-4f5f-b395-aee14262ec22', '1', 'sundynix-pc', '测试用户',   'test',    '$2a$10$trQ.ZH6g.8of45pG/527y.01pSrgJCQX0yoWOezXF8acoKfVlxWeO', 'Tester', '13800000001', 0, NOW(), NOW()),
('c9d1610b-512f-4a27-aac0-e0a26db76ee3', '1', 'sundynix-pc', '运维人员',   'editor',  '$2a$10$trQ.ZH6g.8of45pG/527y.01pSrgJCQX0yoWOezXF8acoKfVlxWeO', 'Editor', '13800000002', 0, NOW(), NOW());

-- ================================================================
-- 6. 用户-角色关联 (sundynix_user_role)
-- ================================================================
INSERT INTO sundynix_user_role (user_id, role_id) VALUES
('b47eae1d-59e5-4cc5-a088-9aaaaba4dddd', '091881d9-10d8-4c01-aa20-22c3988e2a2a'),  -- sundynix -> 超级管理员
('11abce94-082c-4f5f-b395-aee14262ec22', '2cfa0b60-d09e-4b14-8238-962feed60a0c'),  -- test     -> 普通用户
('c9d1610b-512f-4a27-aac0-e0a26db76ee3', '23f0622e-baf7-4733-9447-733dbea1fae4');   -- editor   -> 运维人员

-- ================================================================
-- 完成！测试账号：
--   sundynix / sundynix  (超级管理员，全部权限)
--   test     / 123456    (普通用户，仅 Dashboard + 个人中心)
--   editor   / 123456    (运维人员，Dashboard + 用户中心 + 植物服务)
-- ================================================================
