<?php
require_once '../auth.php';
ensureAdminAjaxAuth();
require_once '../../config/database.php';
header('Content-Type: application/json');
try {
    $database = new Database();
    $db = $database->getConnection();
    $stats = [
        'total' => (int)$db->query("SELECT COUNT(*) FROM service_requests")->fetchColumn(),
        'pending' => (int)$db->query("SELECT COUNT(*) FROM service_requests WHERE job_status_id = 1")->fetchColumn(),
        'in_progress' => (int)$db->query("SELECT COUNT(*) FROM service_requests WHERE job_status_id = 3")->fetchColumn(),
        'completed' => (int)$db->query("SELECT COUNT(*) FROM service_requests WHERE job_status_id = 4")->fetchColumn(),
        'cancelled' => (int)$db->query("SELECT COUNT(*) FROM service_requests WHERE job_status_id = 5")->fetchColumn()
    ];
    echo json_encode(['success' => true, 'stats' => $stats]);
} catch (Exception $e) {
    echo json_encode(['success' => false, 'message' => $e->getMessage()]);
}
?>
