-- ============================================================
-- 种子数据：用于测试登录的初始管理员账号
-- 密码: 123456 (bcrypt hash)
-- 执行方式: psql -U postgres -d crm_erp -f seed.sql
-- ============================================================

-- 1. 插入顶级部门
INSERT INTO sys_departments (id, parent_id, name, sort_order, status)
VALUES (
    'a0000000-0000-0000-0000-000000000001',
    NULL,
    '总部',
    1,
    1
) ON CONFLICT DO NOTHING;

-- 2. 插入超级管理员角色 (data_scope = all)
INSERT INTO sys_roles (id, role_name, data_scope, menu_keys, description, status)
VALUES (
    'b0000000-0000-0000-0000-000000000001',
    '超级管理员',
    'all',
    '["dashboard","customers","customers:detail","products","orders","shipping","finance","settings"]'::JSONB,
    '拥有系统全部权限',
    1
) ON CONFLICT DO NOTHING;

-- 3. 插入管理员用户 (admin / 123456)
--    bcrypt hash of "123456" —— 直接用 Python 生成:
--    from passlib.context import CryptContext; print(CryptContext(schemes=["bcrypt"]).hash("123456"))
INSERT INTO sys_users (id, dept_id, role_id, username, password_hash, real_name, phone, status)
VALUES (
    'c0000000-0000-0000-0000-000000000001',
    'a0000000-0000-0000-0000-000000000001',
    'b0000000-0000-0000-0000-000000000001',
    'admin',
    '$2b$12$N3aYJxXxEeUggclCvnVLgewUFIewfYhAB2fXLlWzI8lY4RoPjCbia',
    '系统管理员',
    '13800000000',
    1
) ON CONFLICT DO NOTHING;
