-- =====================================================
-- 插入测试裁判邀请数据
-- 执行时间: 2025-12-12
-- =====================================================

USE blade;

-- 首先确保有测试赛事数据
-- 假设已经有赛事ID为 1 的数据

-- 首先确保有测试裁判数据
-- 插入测试裁判（如果不存在）
INSERT IGNORE INTO martial_judge (id, name, gender, phone, id_card, referee_type, level, specialty, create_time, update_time, status, is_deleted)
VALUES
(1, '张三', 1, '13800138001', '110101199001011234', 2, '国家级', '太极拳', NOW(), NOW(), 1, 0),
(2, '李四', 1, '13800138002', '110101199002021234', 2, '一级', '长拳', NOW(), NOW(), 1, 0),
(3, '王五', 2, '13800138003', '110101199003031234', 2, '二级', '剑术', NOW(), NOW(), 1, 0),
(4, '赵六', 1, '13800138004', '110101199004041234', 1, '国家级', '刀术', NOW(), NOW(), 1, 0),
(5, '钱七', 2, '13800138005', '110101199005051234', 2, '三级', '棍术', NOW(), NOW(), 1, 0);

-- 插入测试邀请数据
INSERT INTO martial_judge_invite (
    id,
    competition_id,
    judge_id,
    invite_code,
    role,
    invite_status,
    invite_time,
    reply_time,
    reply_note,
    contact_phone,
    contact_email,
    invite_message,
    expire_time,
    is_used,
    create_time,
    update_time,
    status,
    is_deleted
)
VALUES
-- 待回复的邀请
(1, 1, 1, 'INV2025001', 'judge', 0, NOW(), NULL, NULL, '13800138001', 'zhangsan@example.com', '诚邀您担任本次武术比赛的裁判', DATE_ADD(NOW(), INTERVAL 30 DAY), 0, NOW(), NOW(), 1, 0),
(2, 1, 2, 'INV2025002', 'judge', 0, NOW(), NULL, NULL, '13800138002', 'lisi@example.com', '诚邀您担任本次武术比赛的裁判', DATE_ADD(NOW(), INTERVAL 30 DAY), 0, NOW(), NOW(), 1, 0),

-- 已接受的邀请
(3, 1, 3, 'INV2025003', 'judge', 1, DATE_SUB(NOW(), INTERVAL 2 DAY), DATE_SUB(NOW(), INTERVAL 1 DAY), '很荣幸能参加，我会准时到场', '13800138003', 'wangwu@example.com', '诚邀您担任本次武术比赛的裁判', DATE_ADD(NOW(), INTERVAL 30 DAY), 1, DATE_SUB(NOW(), INTERVAL 2 DAY), NOW(), 1, 0),
(4, 1, 4, 'INV2025004', 'chief_judge', 1, DATE_SUB(NOW(), INTERVAL 3 DAY), DATE_SUB(NOW(), INTERVAL 2 DAY), '感谢邀请，我会认真履行裁判长职责', '13800138004', 'zhaoliu@example.com', '诚邀您担任本次武术比赛的裁判长', DATE_ADD(NOW(), INTERVAL 30 DAY), 1, DATE_SUB(NOW(), INTERVAL 3 DAY), NOW(), 1, 0),

-- 已拒绝的邀请
(5, 1, 5, 'INV2025005', 'judge', 2, DATE_SUB(NOW(), INTERVAL 5 DAY), DATE_SUB(NOW(), INTERVAL 4 DAY), '非常抱歉，那段时间有其他安排', '13800138005', 'qianqi@example.com', '诚邀您担任本次武术比赛的裁判', DATE_ADD(NOW(), INTERVAL 30 DAY), 0, DATE_SUB(NOW(), INTERVAL 5 DAY), NOW(), 1, 0);

-- 验证插入结果
SELECT
    ji.id,
    ji.invite_code,
    j.name AS judge_name,
    j.level AS judge_level,
    ji.contact_phone,
    ji.contact_email,
    ji.invite_status,
    CASE ji.invite_status
        WHEN 0 THEN '待回复'
        WHEN 1 THEN '已接受'
        WHEN 2 THEN '已拒绝'
        WHEN 3 THEN '已取消'
        ELSE '未知'
    END AS status_text,
    ji.invite_time,
    ji.reply_time,
    ji.reply_note
FROM
    martial_judge_invite ji
LEFT JOIN martial_judge j ON ji.judge_id = j.id
WHERE
    ji.competition_id = 1
    AND ji.is_deleted = 0
ORDER BY
    ji.id;

SELECT 'Test data inserted successfully!' AS status;
