<?php
// api/debug_roster.php
require_once '../config/database.php';

$date = '2026-02-08';
echo "<h1>Debugging Roster for $date</h1>";

// 1. Get Service
$stmt = $pdo->prepare("SELECT * FROM services WHERE service_date = ?");
$stmt->execute([$date]);
$service = $stmt->fetch(PDO::FETCH_ASSOC);

if (!$service) {
    die("No service found for $date");
}
echo "Found Service ID: " . $service['id'] . " (" . $service['type'] . ")<br>";

// 2. Get Roster
$stmt = $pdo->prepare("SELECT * FROM rosters WHERE service_id = ?");
$stmt->execute([$service['id']]);
$roster = $stmt->fetch(PDO::FETCH_ASSOC);

if (!$roster) {
    die("No roster found for this service.");
}
echo "Found Roster ID: " . $roster['id'] . " (Status: " . $roster['status'] . ")<br>";

// 3. Get Assignments
$stmt = $pdo->prepare("SELECT role_name, person_name FROM roster_assignments WHERE roster_id = ?");
$stmt->execute([$roster['id']]);
$assignments = $stmt->fetchAll(PDO::FETCH_ASSOC);

echo "<h2>Assignments in DB (" . count($assignments) . ")</h2>";
echo "<pre>";
foreach ($assignments as $a) {
    echo "[" . $a['role_name'] . "] => " . $a['person_name'] . "\n";
}
echo "</pre>";

// 4. Compare with Config
require_once '../includes/role_config.php';
echo "<h2>Config Roles</h2>";
echo "<pre>";
print_r($role_categories);
echo "</pre>";
?>
