INSERT INTO upms.tb_sys_tenant (
    tenant_id, parent_tenant_id, tenant_name, tenant_type, adcode, tenant_path
) VALUES
    ('SCH-HQ', NULL, 'K12Study 总校', 'HEAD_SCHOOL', '330100', '/SCH-HQ/'),
    ('SCH-ZJ-HZ-01', 'SCH-HQ', '杭州分校', 'CITY_SCHOOL', '330100', '/SCH-HQ/SCH-ZJ-HZ-01/')
ON CONFLICT (tenant_id) DO NOTHING;

INSERT INTO upms.tb_sys_dept (
    dept_id, parent_dept_id, tenant_id, dept_name, dept_type, adcode, tenant_path, dept_path
) VALUES
    ('DEPT-HQ', NULL, 'SCH-HQ', '总校教学部', 'GRADE', '330100', '/SCH-HQ/', '/DEPT-HQ/'),
    ('DEPT-HQ-MATH', 'DEPT-HQ', 'SCH-HQ', '数学学科组', 'SUBJECT', '330100', '/SCH-HQ/', '/DEPT-HQ/DEPT-HQ-MATH/'),
    ('DEPT-HQ-ADMIN', 'DEPT-HQ', 'SCH-HQ', '总校运营组', 'ADMIN', '330100', '/SCH-HQ/', '/DEPT-HQ/DEPT-HQ-ADMIN/')
ON CONFLICT (dept_id) DO NOTHING;

INSERT INTO upms.tb_sys_user (
    user_id, username, display_name, password_hash, adcode, tenant_id, tenant_path, dept_id, dept_path
) VALUES
    ('U10001', 'admin', 'K12Study 管理员', '$2a$10$bootstrap', '330100', 'SCH-HQ', '/SCH-HQ/', 'DEPT-HQ-ADMIN', '/DEPT-HQ/DEPT-HQ-ADMIN/')
ON CONFLICT (user_id) DO NOTHING;

INSERT INTO upms.tb_sys_role (
    role_id, role_code, role_name, adcode, tenant_id, tenant_path, dept_id, dept_path
) VALUES
    ('ROLE-ORG-ADMIN', 'ORG_ADMIN', '机构管理员', '330100', 'SCH-HQ', '/SCH-HQ/', 'DEPT-HQ-ADMIN', '/DEPT-HQ/DEPT-HQ-ADMIN/')
ON CONFLICT (role_id) DO NOTHING;

INSERT INTO upms.tb_sys_permission (
    permission_id, permission_code, permission_name, adcode, tenant_id, tenant_path, dept_id, dept_path
) VALUES
    ('PERM-DASHBOARD', 'dashboard:view', '查看控制台', '330100', 'SCH-HQ', '/SCH-HQ/', 'DEPT-HQ-ADMIN', '/DEPT-HQ/DEPT-HQ-ADMIN/'),
    ('PERM-TENANT', 'tenant:view', '查看租户组织', '330100', 'SCH-HQ', '/SCH-HQ/', 'DEPT-HQ-ADMIN', '/DEPT-HQ/DEPT-HQ-ADMIN/')
ON CONFLICT (permission_id) DO NOTHING;

INSERT INTO upms.tb_sys_menu (
    route_id, parent_route_id, route_path, route_name, component_key, layout_type, title, icon, permission_code,
    hidden, adcode, tenant_id, tenant_path, dept_id, dept_path
) VALUES
    ('ROUTE-DASHBOARD', NULL, '/', 'dashboard', 'dashboard', 'SIDEBAR', '控制台', 'layout-dashboard', 'dashboard:view', FALSE,
        '330100', 'SCH-HQ', '/SCH-HQ/', 'DEPT-HQ-ADMIN', '/DEPT-HQ/DEPT-HQ-ADMIN/'),
    ('ROUTE-TENANT', NULL, '/tenant', 'tenant-management', 'tenant', 'SIDEBAR', '租户组织', 'building-2', 'tenant:view', FALSE,
        '330100', 'SCH-HQ', '/SCH-HQ/', 'DEPT-HQ-ADMIN', '/DEPT-HQ/DEPT-HQ-ADMIN/')
ON CONFLICT (route_id) DO NOTHING;
