<?php
require_once '../db/config.php';
session_start();

header('Content-Type: application/json');

if (!isset($_SESSION['user_id'])) {
    echo json_encode(['status' => 'unauthorized']);
    exit;
}

$user_id = $_SESSION['user_id'];
$pdo = db();

$stmt = $pdo->prepare("SELECT status, bank_account_info FROM fiat_orders WHERE user_id = ? AND status IN ('matching', 'matched', 'submitting') ORDER BY id DESC LIMIT 1");
$stmt->execute([$user_id]);
$order = $stmt->fetch();

if ($order) {
    echo json_encode([
        'status' => $order['status'],
        'account_info' => $order['bank_account_info']
    ]);
} else {
    echo json_encode(['status' => 'none']);
}
