-- 合同管理菜单和权限初始化脚本

-- 1. 菜单 SQL
INSERT INTO system_menu(
    name, permission, type, sort, parent_id,
    path, icon, component, status, component_name
)
VALUES (
    '合同管理', '', 2, 5, 5055,
    'contract', 'documentation', 'asset/contract/index', 0, 'Contract'
);

-- 获取刚插入的菜单ID
SET @menuId = LAST_INSERT_ID();

-- 合同管理按钮权限
INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status)
VALUES
    ('合同查询', 'asset:contract:query', 3, 1, @menuId, '', '', '', 0),
    ('合同创建', 'asset:contract:create', 3, 2, @menuId, '', '', '', 0),
    ('合同更新', 'asset:contract:update', 3, 3, @menuId, '', '', '', 0),
    ('合同删除', 'asset:contract:delete', 3, 4, @menuId, '', '', '', 0),
    ('合同导出', 'asset:contract:export', 3, 5, @menuId, '', '', '', 0),
    ('提交审批', 'asset:contract:submit-approval', 3, 6, @menuId, '', '', '', 0),
    ('撤回审批', 'asset:contract:withdraw-approval', 3, 7, @menuId, '', '', '', 0),
    ('终止合同', 'asset:contract:terminate', 3, 8, @menuId, '', '', '', 0),
    ('续签合同', 'asset:contract:renew', 3, 9, @menuId, '', '', '', 0);

-- 2. 字典类型
INSERT INTO system_dict_type (name, type, status, remark, creator, create_time, updater, update_time, deleted)
VALUES
    ('合同类型', 'asset_contract_type', 0, '车辆租赁合同类型', 'admin', NOW(), 'admin', NOW(), b'0'),
    ('合同审批状态', 'asset_contract_approval_status', 0, '合同审批状态', 'admin', NOW(), 'admin', NOW(), b'0'),
    ('合同状态', 'asset_contract_status', 0, '合同业务状态', 'admin', NOW(), 'admin', NOW(), b'0'),
    ('车辆订单状态', 'asset_contract_vehicle_status', 0, '合同车辆订单状态', 'admin', NOW(), 'admin', NOW(), b'0');

-- 3. 字典数据 - 合同类型
INSERT INTO system_dict_data (dict_type, label, value, sort, status, remark, creator, create_time, updater, update_time, deleted)
VALUES
    ('asset_contract_type', '试用合同', '1', 1, 0, '试用期合同', 'admin', NOW(), 'admin', NOW(), b'0'),
    ('asset_contract_type', '正式合同', '2', 2, 0, '正式租赁合同', 'admin', NOW(), 'admin', NOW(), b'0');

-- 4. 字典数据 - 合同审批状态
INSERT INTO system_dict_data (dict_type, label, value, sort, status, color_type, remark, creator, create_time, updater, update_time, deleted)
VALUES
    ('asset_contract_approval_status', '草稿', '0', 1, 0, 'info', '草稿状态', 'admin', NOW(), 'admin', NOW(), b'0'),
    ('asset_contract_approval_status', '审批中', '1', 2, 0, 'warning', '审批中', 'admin', NOW(), 'admin', NOW(), b'0'),
    ('asset_contract_approval_status', '审批通过', '2', 3, 0, 'success', '审批通过', 'admin', NOW(), 'admin', NOW(), b'0'),
    ('asset_contract_approval_status', '审批拒绝', '3', 4, 0, 'danger', '审批拒绝', 'admin', NOW(), 'admin', NOW(), b'0'),
    ('asset_contract_approval_status', '已撤回', '4', 5, 0, 'info', '已撤回', 'admin', NOW(), 'admin', NOW(), b'0');

-- 5. 字典数据 - 合同状态
INSERT INTO system_dict_data (dict_type, label, value, sort, status, color_type, remark, creator, create_time, updater, update_time, deleted)
VALUES
    ('asset_contract_status', '草稿', '0', 1, 0, 'info', '草稿状态', 'admin', NOW(), 'admin', NOW(), b'0'),
    ('asset_contract_status', '待生效', '1', 2, 0, 'warning', '待生效', 'admin', NOW(), 'admin', NOW(), b'0'),
    ('asset_contract_status', '进行中', '2', 3, 0, 'success', '进行中', 'admin', NOW(), 'admin', NOW(), b'0'),
    ('asset_contract_status', '已到期', '3', 4, 0, 'info', '已到期', 'admin', NOW(), 'admin', NOW(), b'0'),
    ('asset_contract_status', '已终止', '4', 5, 0, 'danger', '已终止', 'admin', NOW(), 'admin', NOW(), b'0'),
    ('asset_contract_status', '已续签', '5', 6, 0, 'primary', '已续签', 'admin', NOW(), 'admin', NOW(), b'0');

-- 6. 字典数据 - 车辆订单状态
INSERT INTO system_dict_data (dict_type, label, value, sort, status, color_type, remark, creator, create_time, updater, update_time, deleted)
VALUES
    ('asset_contract_vehicle_status', '待交车', '0', 1, 0, 'warning', '待交车', 'admin', NOW(), 'admin', NOW(), b'0'),
    ('asset_contract_vehicle_status', '已交车', '1', 2, 0, 'success', '已交车', 'admin', NOW(), 'admin', NOW(), b'0'),
    ('asset_contract_vehicle_status', '已退车', '2', 3, 0, 'info', '已退车', 'admin', NOW(), 'admin', NOW(), b'0');
