# MySQL测试数据插入脚本
# 需要先安装MySQL客户端

Write-Host "正在连接MySQL数据库并插入测试数据..." -ForegroundColor Green

# MySQL连接参数
$mysqlHost = "localhost"
$mysqlPort = "3306"
$mysqlUser = "root"
$mysqlPassword = "177615"
$mysqlDatabase = "aigc"

# 检查MySQL是否可用
try {
    $testConnection = mysql -h $mysqlHost -P $mysqlPort -u $mysqlUser -p$mysqlPassword -e "SELECT 1;" 2>$null
    if ($LASTEXITCODE -eq 0) {
        Write-Host "MySQL连接成功!" -ForegroundColor Green
    } else {
        Write-Host "MySQL连接失败，请检查MySQL服务是否运行" -ForegroundColor Red
        exit 1
    }
} catch {
    Write-Host "MySQL客户端未安装或不在PATH中" -ForegroundColor Red
    Write-Host "请安装MySQL客户端或使用MySQL Workbench执行 insert_test_data.sql" -ForegroundColor Yellow
    exit 1
}

# 执行SQL脚本
Write-Host "正在执行SQL脚本..." -ForegroundColor Yellow
mysql -h $mysqlHost -P $mysqlPort -u $mysqlUser -p$mysqlPassword $mysqlDatabase -e "
DELETE FROM users WHERE username IN ('demo', 'admin', 'testuser', 'mingzi_FBx7foZYDS7inLQb', '15538239326');

INSERT INTO users (username, email, password_hash, role, points) VALUES 
('demo', 'demo@example.com', 'demo', 'ROLE_USER', 100),
('admin', 'admin@example.com', 'admin123', 'ROLE_ADMIN', 200),
('testuser', 'testuser@example.com', 'test123', 'ROLE_USER', 75),
('mingzi_FBx7foZYDS7inLQb', 'mingzi@example.com', '123456', 'ROLE_USER', 25),
('15538239326', '15538239326@example.com', '0627', 'ROLE_USER', 50);

SELECT username, email, role, points FROM users WHERE username IN ('demo', 'admin', 'testuser', 'mingzi_FBx7foZYDS7inLQb', '15538239326');
"

if ($LASTEXITCODE -eq 0) {
    Write-Host "测试数据插入成功!" -ForegroundColor Green
    Write-Host "现在可以使用以下账号登录:" -ForegroundColor Cyan
    Write-Host "  - 普通用户: demo / demo" -ForegroundColor White
    Write-Host "  - 管理员: admin / admin123" -ForegroundColor White
    Write-Host "  - 测试用户: testuser / test123" -ForegroundColor White
    Write-Host "  - 个人主页: mingzi_FBx7foZYDS7inLQb / 123456" -ForegroundColor White
    Write-Host "  - 手机号测试: 15538239326 / 0627" -ForegroundColor White
} else {
    Write-Host "测试数据插入失败!" -ForegroundColor Red
}
