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

$id = filterRequest("id");

$sql = "SELECT * FROM `passengers` WHERE `id` = :id";
$stmt = $con->prepare($sql);
$stmt->bindParam(':id', $id, PDO::PARAM_STR);
$stmt->execute();
$result = $stmt->fetch(PDO::FETCH_ASSOC);

if ($result) {
    unset($result['password']); // إخفاء الباسورد

    // فك تشفير الحقول الحساسة
    $fieldsToDecrypt = [
        'phone', 'email', 'gender', 'birthdate', 'site',
        'first_name', 'last_name', 'sosPhone',
        'education', 'employmentType', 'maritalStatus'
    ];

    foreach ($fieldsToDecrypt as $field) {
        if (isset($result[$field])) {
            $result[$field] = $encryptionHelper->decryptData($result[$field]);
        }
    }

    echo json_encode([
        "status" => "success",
        "data" => $result
    ]);
} else {
    jsonError("Failed to retrieve passenger data");
}
?>