-- =====================================================
-- 添加封禁系统测试数据
-- =====================================================

-- 1. 确保封禁表存在
CREATE TABLE IF NOT EXISTS eb_user_ban (
    id INT AUTO_INCREMENT PRIMARY KEY,
    user_id INT NOT NULL COMMENT '被封禁用户ID',
    ban_type VARCHAR(20) DEFAULT 'permanent' COMMENT '封禁类型: permanent-永久, temporary-临时',
    reason VARCHAR(500) COMMENT '封禁原因',
    duration_days INT DEFAULT NULL COMMENT '封禁天数(临时封禁)',
    expire_time DATETIME DEFAULT NULL COMMENT '封禁到期时间',
    operator_id INT DEFAULT 0 COMMENT '操作人ID',
    status TINYINT DEFAULT 1 COMMENT '状态: 1-生效中, 0-已解除',
    create_time DATETIME DEFAULT CURRENT_TIMESTAMP,
    update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    INDEX idx_user_id (user_id),
    INDEX idx_status (status)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户封禁表';

CREATE TABLE IF NOT EXISTS eb_room_ban (
    id INT AUTO_INCREMENT PRIMARY KEY,
    room_id INT NOT NULL COMMENT '被封禁房间ID',
    ban_type VARCHAR(20) DEFAULT 'permanent' COMMENT '封禁类型: permanent-永久, temporary-临时',
    reason VARCHAR(500) COMMENT '封禁原因',
    duration_days INT DEFAULT NULL COMMENT '封禁天数(临时封禁)',
    expire_time DATETIME DEFAULT NULL COMMENT '封禁到期时间',
    operator_id INT DEFAULT 0 COMMENT '操作人ID',
    status TINYINT DEFAULT 1 COMMENT '状态: 1-生效中, 0-已解除',
    create_time DATETIME DEFAULT CURRENT_TIMESTAMP,
    update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    INDEX idx_room_id (room_id),
    INDEX idx_status (status)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='房间封禁表';

-- 2. 添加用户封禁测试数据
INSERT INTO eb_user_ban (user_id, ban_type, reason, duration_days, expire_time, operator_id, status, create_time) VALUES
(43, 'permanent', '发布违规内容', NULL, NULL, 1, 1, NOW() - INTERVAL 2 DAY),
(100, 'temporary', '恶意刷屏', 7, NOW() + INTERVAL 5 DAY, 1, 1, NOW() - INTERVAL 2 DAY),
(101, 'temporary', '骚扰其他用户', 30, NOW() + INTERVAL 28 DAY, 1, 1, NOW() - INTERVAL 2 DAY),
(102, 'permanent', '传播不良信息', NULL, NULL, 1, 0, NOW() - INTERVAL 10 DAY)
ON DUPLICATE KEY UPDATE reason = VALUES(reason);

-- 3. 添加房间封禁测试数据
INSERT INTO eb_room_ban (room_id, ban_type, reason, duration_days, expire_time, operator_id, status, create_time) VALUES
(1, 'temporary', '直播内容违规', 3, NOW() + INTERVAL 1 DAY, 1, 1, NOW() - INTERVAL 2 DAY),
(2, 'permanent', '严重违规行为', NULL, NULL, 1, 1, NOW() - INTERVAL 5 DAY),
(3, 'temporary', '未经授权的商业推广', 7, NOW() + INTERVAL 5 DAY, 1, 1, NOW() - INTERVAL 2 DAY),
(4, 'permanent', '涉及敏感内容', NULL, NULL, 1, 0, NOW() - INTERVAL 15 DAY)
ON DUPLICATE KEY UPDATE reason = VALUES(reason);

-- 4. 验证数据
SELECT '=== 用户封禁数据 ===' as info;
SELECT ub.*, u.nickname, u.phone 
FROM eb_user_ban ub 
LEFT JOIN eb_user u ON ub.user_id = u.uid
ORDER BY ub.create_time DESC;

SELECT '=== 房间封禁数据 ===' as info;
SELECT rb.*, lr.title as room_name, lr.streamer_name
FROM eb_room_ban rb
LEFT JOIN eb_live_room lr ON rb.room_id = lr.id
ORDER BY rb.create_time DESC;

SELECT '=== 统计 ===' as info;
SELECT 
    (SELECT COUNT(*) FROM eb_user_ban) as 用户封禁总数,
    (SELECT COUNT(*) FROM eb_user_ban WHERE status = 1) as 用户封禁生效中,
    (SELECT COUNT(*) FROM eb_room_ban) as 房间封禁总数,
    (SELECT COUNT(*) FROM eb_room_ban WHERE status = 1) as 房间封禁生效中;
