<?php
require_once __DIR__ . '/../lib.php';

$user = hw_get_auth_user();
if (!$user || !in_array('superadmin', $user['roles'])) {
    hw_json(['success' => false, 'message' => 'Unauthorized'], 401);
}

$input = hw_input_json();
$id = (int)($input['id'] ?? 0);

if (!$id) {
    hw_json(['success' => false, 'message' => 'Appointment ID required'], 400);
}

try {
    $pdo = hw_db();
    $stmt = $pdo->prepare("DELETE FROM appointments WHERE id = ?");
    $stmt->execute([$id]);

    hw_json(['success' => true, 'message' => 'Appointment deleted successfully']);
} catch (Exception $e) {
    hw_json(['success' => false, 'message' => 'Server error'], 500);
}
?>