-- 初始租户与角色
INSERT INTO tenant (id, tenant_name, status, created_by, updated_by)
VALUES (1, '默认单位', 'ACTIVE', 0, 0)
ON DUPLICATE KEY UPDATE updated_at = CURRENT_TIMESTAMP;

INSERT INTO role (id, tenant_id, role_code, role_name, status, created_by, updated_by)
VALUES
    (101, 1, 'TENANT_ADMIN', '单位管理员', 'ENABLED', 0, 0),
    (102, 1, 'PROJECT_OWNER', '项目负责人', 'ENABLED', 0, 0),
    (103, 1, 'EXECUTOR', '项目执行人', 'ENABLED', 0, 0),
    (104, 1, 'AUDITOR', '审核人', 'ENABLED', 0, 0),
    (105, 1, 'FINANCE', '财务', 'ENABLED', 0, 0)
ON DUPLICATE KEY UPDATE updated_at = CURRENT_TIMESTAMP;

-- 权限字典
INSERT INTO permission (id, permission_code, permission_name, module)
VALUES
    (1001, 'project.create', '创建项目', 'project'),
    (1002, 'project.freeze', '冻结项目', 'project'),
    (1003, 'meeting.create', '创建会议', 'meeting'),
    (1004, 'meeting.submit', '会议级提交', 'meeting'),
    (1005, 'audit.approve', '审核通过', 'audit'),
    (1006, 'audit.reject', '审核拒绝', 'audit'),
    (1007, 'audit.return', '审核退回', 'audit'),
    (1008, 'finance.payment.confirm', '支付确认', 'finance'),
    (1009, 'meeting.read', '查看会议', 'meeting')
ON DUPLICATE KEY UPDATE permission_name = VALUES(permission_name);

-- 错误码字典
INSERT INTO error_code_dict (id, code, message, category)
VALUES
    (1, 10001, '参数校验失败', 'COMMON'),
    (2, 10002, '请求幂等冲突', 'COMMON'),
    (3, 10003, '资源不存在', 'COMMON'),
    (4, 20001, '无操作权限', 'PERMISSION'),
    (5, 30001, '状态不允许流转', 'STATE'),
    (6, 30003, '审核任务已处理', 'STATE'),
    (7, 40003, '支付状态不允许', 'FINANCE'),
    (8, 90001, '系统内部异常', 'SYSTEM')
ON DUPLICATE KEY UPDATE message = VALUES(message);
