<?php
// api/setup_submissions.php - 建立截圖證據資料表
header("Content-Type: text/html; charset=utf-8");
require_once 'db.php';

try {
    // 建立 task_submissions 表
    $sql = "CREATE TABLE IF NOT EXISTS task_submissions (
        id INT AUTO_INCREMENT PRIMARY KEY,
        task_id INT NOT NULL,
        user_id INT NOT NULL,
        proof_img LONGTEXT NOT NULL COMMENT '截圖路徑 (Base64 或 網址)',
        status ENUM('pending', 'approved', 'rejected') DEFAULT 'pending' COMMENT '審核狀態',
        created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
        INDEX (user_id),
        INDEX (task_id),
        INDEX (status)
    )";
    $pdo->exec($sql);
    
    echo "
    <div style='background:#121212; color:#00ff88; padding:40px; text-align:center; font-family:sans-serif; height:100vh; display:flex; flex-direction:column; justify-content:center;'>
        <h1>✅ 證據地窖建設完成！</h1>
        <p>資料表 `task_submissions` 已成功建立。</p>
        <p>礦工現在可以順利上傳截圖了！</p>
        <a href='../radar.html' style='display:inline-block; margin-top:20px; padding:15px 30px; background:#ffd700; color:#000; text-decoration:none; font-weight:bold; border-radius:50px;'>🚀 返回天眼雷達測試上傳</a>
    </div>";

} catch (PDOException $e) {
    echo "<h2 style='color:red;'>❌ 錯誤：" . $e->getMessage() . "</h2>";
}
?>