<?php
require_once(__DIR__ . '/../json_db.php');
session_start();
header('Content-Type: application/json');

$id = intval(isset($_GET['user_id']) ? $_GET['user_id'] : (isset($_GET['id']) ? $_GET['id'] : 0));
$user = $jsonDB->findById('users', $id);

if ($user) {
    echo json_encode([
        'id' => $user['id'],
        'username' => isset($user['username']) ? $user['username'] : '',
        'ssn' => isset($user['ssn']) ? $user['ssn'] : '',
        'phone' => isset($user['phone']) ? $user['phone'] : '',
        'date' => isset($user['date']) ? $user['date'] : '',
        'insurance_company' => isset($user['insurance_company']) ? $user['insurance_company'] : '',
        'insurance_price' => isset($user['insurance_price']) ? $user['insurance_price'] : '',
        'account_type' => isset($user['account_type']) ? $user['account_type'] : '',
        'address' => isset($user['address']) ? $user['address'] : '',
        'message' => isset($user['message']) ? $user['message'] : '',
        'page' => isset($user['page']) ? $user['page'] : '',
        'created_at' => isset($user['created_at']) ? $user['created_at'] : ''
    ]);
} else {
    echo json_encode(['error' => 'User not found']);
}
