<?php
header("Content-Type: application/json");
header("Access-Control-Allow-Origin: *");

include '../../config.php';

// Fetch only names and phone
$sql = "SELECT `id`, `firstname`, `middlename`, `lastname`, `phone` FROM `customers`";
$result = $conn->query($sql);

$customers = [];
if ($result) {
    while ($row = $result->fetch_assoc()) {
        $fullName = trim($row['firstname'] . ' ' . $row['middlename'] . ' ' . $row['lastname']);
        $customers[] = [
            'id'        => (string)$row['id'],
            'full_name' => $fullName,
            'phone'     => $row['phone'],
        ];
    }
}

echo json_encode($customers);
$conn->close();
