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

$sql = "
SELECT
    d.phone,
    d.id,
    d.name_arabic,
    dt.token
FROM
    `driver` d
LEFT JOIN driverToken dt ON
    dt.captain_id = d.id
";

$stmt = $con->prepare($sql);
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);

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

if ($stmt->rowCount() > 0) {
    jsonSuccess($result);
} else {
    jsonError("No records found");
}
?>