<?php
// =============================================================
//  GET /api/v1/admin_reference/specialties_list[?status=Active|Inactive]
// =============================================================

require_once __DIR__ . '/../_bootstrap.php';

if ($_SERVER['REQUEST_METHOD'] !== 'GET') {
    Api::error(405, 'MethodNotAllowed', 'Use GET');
}

api_authenticate();
api_require_permission('manage_specialties');

$status = (string)($_GET['status'] ?? 'Active');
if (!in_array($status, ['Active', 'Inactive'], true)) $status = 'Active';

$stmt = $conn->prepare("
    SELECT id, name, description, status,
           deactivated_by, deactivation_reason, deactivated_at
    FROM specialty
    WHERE status = ?
    ORDER BY name
");
$stmt->bind_param('s', $status);
$stmt->execute();
$specialties = $stmt->get_result()->fetch_all(MYSQLI_ASSOC);
$stmt->close();

Api::success(['specialties' => $specialties]);
