<?php
/**
 * todaysAppointment.php
 * Returns total number of appointments created today
 */

require_once __DIR__ . '/../../dripend/includes/db.php';

header('Content-Type: application/json');

// Ensure DB connection exists
if (!isset($conn) || !$conn) {
    echo json_encode(['count' => 0]);
    exit;
}

// Get current date (server authoritative date)
$today = date('Y-m-d');

// Count appointments created today
$stmt = $conn->prepare("
    SELECT COUNT(*) AS total
    FROM appointment
    WHERE DATE(created_at) = ?
");

$stmt->bind_param('s', $today);
$stmt->execute();

$result = $stmt->get_result();
$row = $result->fetch_assoc();

$total = $row ? (int)$row['total'] : 0;

$stmt->close();

echo json_encode([
    'count' => $total
]);
