<?php

require_once __DIR__ . '/../connect.php';
$phoneNumber = filterRequest("phone_number");

$sql = "SELECT
    d.id, d.name_arabic, d.phone, d.created_at
FROM
    `driver` d
WHERE
    d.id NOT IN (SELECT driverID FROM CarRegistration)  
ORDER BY `d`.`created_at` DESC
";

$stmt = $con->prepare($sql);
$stmt->execute();

if ($stmt->rowCount() > 0) {
    $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);

    // فك التشفير للحقول الحساسة
    foreach ($rows as &$row) {
        $row['phone'] = $encryptionHelper->decryptData($row['phone']);
        $row['name_arabic'] = $encryptionHelper->decryptData($row['name_arabic']);
    }

    jsonSuccess($rows);
} else {
    jsonError("No Car verified yet found");
}