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

$sql = "
SELECT
    `id`,
    `phone`,
    `email`,
    `gender`,
    `birthdate`,
    `first_name`,
    `last_name`,
    `sosPhone`
FROM
    `passengers`
";

$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['email'] = $encryptionHelper->decryptData($row['email']);
        $row['gender'] = $encryptionHelper->decryptData($row['gender']);
        $row['birthdate'] = $encryptionHelper->decryptData($row['birthdate']);
        $row['first_name'] = $encryptionHelper->decryptData($row['first_name']);
        $row['last_name'] = $encryptionHelper->decryptData($row['last_name']);
        $row['sosPhone'] = $encryptionHelper->decryptData($row['sosPhone']);
    }

    jsonSuccess($rows);
} else {
    jsonError("No wallet record found");
}
?>