-- 网络验证平台种子数据
USE verification_platform;

-- 插入默认管理员用户
INSERT INTO users (username, email, password, role, status) VALUES 
('admin', 'admin@example.com', '$2a$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', 'admin', 'active');

-- 插入测试开发者用户
INSERT INTO users (username, email, password, role, status) VALUES 
('developer1', 'dev1@example.com', '$2a$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', 'developer', 'active'),
('developer2', 'dev2@example.com', '$2a$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', 'developer', 'active');

-- 插入测试代理用户
INSERT INTO users (username, email, password, role, status) VALUES 
('agent1', 'agent1@example.com', '$2a$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', 'agent', 'active'),
('agent2', 'agent2@example.com', '$2a$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', 'agent', 'active');

-- 插入代理信息
INSERT INTO agents (user_id, level, commission) VALUES 
(3, 1, 0.1000),  -- agent1
(4, 1, 0.1000);  -- agent2

-- 插入测试应用
INSERT INTO applications (user_id, name, description, billing_type, encrypt_type, secret_key, bind_type, max_devices, multi_open) VALUES 
(2, '测试应用1', '这是一个测试应用', 'subscription', 'aes', 'test-secret-key-1', 'device', 1, false),
(2, '测试应用2', '这是另一个测试应用', 'time', 'rc4', 'test-secret-key-2', 'ip', 3, true),
(3, '测试应用3', '开发者2的测试应用', 'point', 'aes', 'test-secret-key-3', 'none', 0, true);

-- 插入测试卡密类型
INSERT INTO card_types (user_id, name, billing_type, value, price, description) VALUES 
(2, '天卡', 'subscription', 1, 1.00, '1天有效期'),
(2, '周卡', 'subscription', 7, 6.00, '7天有效期'),
(2, '月卡', 'subscription', 30, 25.00, '30天有效期'),
(2, '季卡', 'subscription', 90, 70.00, '90天有效期'),
(2, '年卡', 'subscription', 365, 280.00, '365天有效期'),
(2, '永久卡', 'subscription', 0, 999.00, '永久有效'),
(2, '时长卡-1小时', 'time', 60, 1.00, '1小时在线时长'),
(2, '时长卡-10小时', 'time', 600, 9.00, '10小时在线时长'),
(2, '点卡-100点', 'point', 100, 5.00, '100点数'),
(2, '点卡-500点', 'point', 500, 20.00, '500点数');

-- 插入测试卡密
INSERT INTO cards (card_type_id, card_key, status) VALUES 
(1, 'TEST-DAY-CARD-001', 'unused'),
(1, 'TEST-DAY-CARD-002', 'unused'),
(2, 'TEST-WEEK-CARD-001', 'unused'),
(3, 'TEST-MONTH-CARD-001', 'unused'),
(4, 'TEST-SEASON-CARD-001', 'unused'),
(5, 'TEST-YEAR-CARD-001', 'unused'),
(6, 'TEST-PERMANENT-CARD-001', 'unused'),
(7, 'TEST-HOUR-CARD-001', 'unused'),
(8, 'TEST-10HOUR-CARD-001', 'unused'),
(9, 'TEST-100POINT-CARD-001', 'unused'),
(10, 'TEST-500POINT-CARD-001', 'unused');

-- 插入测试版本
INSERT INTO versions (application_id, version, file_path, file_size, force_update, description) VALUES 
(1, '1.0.0', '/uploads/test-app-1-1.0.0.exe', 1024000, false, '初始版本'),
(1, '1.1.0', '/uploads/test-app-1-1.1.0.exe', 1025000, false, '修复了一些bug'),
(1, '2.0.0', '/uploads/test-app-1-2.0.0.exe', 2048000, true, '重大更新，强制升级'),
(2, '1.0.0', '/uploads/test-app-2-1.0.0.exe', 512000, false, '初始版本'),
(3, '1.0.0', '/uploads/test-app-3-1.0.0.exe', 768000, false, '初始版本');

-- 插入测试工单
INSERT INTO tickets (user_id, title, content, type, status, priority) VALUES 
(2, '关于卡密生成的问题', '我在生成卡密时遇到了问题，无法正常生成卡密。', 'developer', 'open', 'normal'),
(3, '代理权限申请', '我想申请代理权限，希望能够销售卡密。', 'developer', 'open', 'low'),
(4, '用户反馈问题', '有用户反映卡密无法使用，请协助处理。', 'agent', 'processing', 'high');

-- 插入测试日志
INSERT INTO logs (user_id, action, resource, details, ip_address, user_agent) VALUES 
(1, 'login', 'system', '管理员登录系统', '127.0.0.1', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'),
(2, 'create', 'application', '创建测试应用1', '127.0.0.1', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'),
(2, 'generate', 'card', '生成测试卡密', '127.0.0.1', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'),
(3, 'create', 'application', '创建测试应用3', '127.0.0.1', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'),
(4, 'create', 'ticket', '提交工单', '127.0.0.1', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36');

-- 插入测试订单
INSERT INTO orders (user_id, order_no, amount, status) VALUES 
(2, 'ORDER20240101001', 1.00, 'paid'),
(2, 'ORDER20240101002', 6.00, 'paid'),
(3, 'ORDER20240101003', 5.00, 'pending'),
(4, 'ORDER20240101004', 25.00, 'paid');

-- 插入测试用户设备
INSERT INTO user_devices (user_id, application_id, device_id, device_name, ip_address, status) VALUES 
(2, 1, 'DEVICE-001', '测试设备1', '192.168.1.100', 'active'),
(2, 1, 'DEVICE-002', '测试设备2', '192.168.1.101', 'active'),
(3, 2, 'DEVICE-003', '测试设备3', '192.168.1.102', 'inactive');

-- 插入测试用户变量
INSERT INTO user_variables (user_id, application_id, var_name, var_value, var_type) VALUES 
(2, 1, 'level', '5', 'number'),
(2, 1, 'vip_status', 'true', 'boolean'),
(2, 1, 'custom_data', '{"key": "value", "num": 123}', 'json'),
(3, 2, 'score', '1000', 'number'),
(3, 2, 'nickname', 'TestUser', 'string');

-- 插入测试云端数据
INSERT INTO cloud_data (user_id, application_id, data_type, key_name, data_value, description) VALUES 
(2, 1, 'constant', 'app_version', '1.0.0', '应用版本号'),
(2, 1, 'constant', 'api_url', 'https://api.example.com', 'API地址'),
(2, 1, 'variable', 'maintenance_mode', 'false', '维护模式开关'),
(3, 2, 'constant', 'max_connections', '100', '最大连接数'),
(3, 2, 'variable', 'current_users', '50', '当前用户数');

-- 插入测试风控黑名单
INSERT INTO risk_blacklist (user_id, application_id, blacklist_type, target_value, reason, status) VALUES 
(2, 1, 'ip', '192.168.1.200', '恶意请求', 'active'),
(2, 1, 'device', 'DEVICE-BANNED-001', '设备异常', 'active'),
(3, 2, 'account', 'baduser001', '违规操作', 'active');