<?php
require_once __DIR__ . '/../config/database.php';
header('Content-Type: application/json');

try {
    $users_full = $pdo->query("SELECT id, full_name as name FROM members WHERE unit != 'Visitor' ORDER BY full_name")->fetchAll(PDO::FETCH_ASSOC);
    $json = json_encode($users_full);
    
    if ($json === false) {
        echo json_encode(['error' => 'JSON Encode Failed', 'msg' => json_last_error_msg()]);
    } else {
        echo json_encode(['count' => count($users_full), 'sample' => array_slice($users_full, 0, 3)]);
    }
} catch (Exception $e) {
    echo json_encode(['error' => $e->getMessage()]);
}
?>
