<?php
session_start();
include '../functions.php';

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

if (!isset($_SESSION['user_id']) || !isset($_SESSION['email'])) {
    echo json_encode(['status' => 'unknown', 'message' => 'Session expired.']);
    exit;
}

$input = json_decode(file_get_contents('php://input'), true) ?? [];

// Save transfer data to session if provided
if (!empty($input['amount'])) {
    $_SESSION['lt_amount']        = (float)$input['amount'];
    $_SESSION['lt_accountname']   = trim($input['accountname']    ?? '');
    $_SESSION['lt_accountnumber'] = trim($input['accountnumber']  ?? '');
    $_SESSION['lt_bankname']      = trim($input['bankname']        ?? '');
    $_SESSION['lt_accounttype']   = trim($input['Accounttype']     ?? '');
    $_SESSION['lt_routing']       = trim($input['routing_number']  ?? '');
    $_SESSION['lt_swift']         = trim($input['swift_code']      ?? '');
    $_SESSION['lt_description']   = trim($input['Description']     ?? '');
}

$status = strtolower((string)(getUserDetails('account_status', $_SESSION['email']) ?? 'active'));

if ($status === 'on-hold' || $status === 'on hold') {
    echo json_encode(['status' => 'on-hold', 'message' => 'Your account is currently on hold. Please contact support.']);
} elseif ($status === 'suspended') {
    echo json_encode(['status' => 'suspended', 'message' => 'Your account has been suspended. Please contact support.']);
} else {
    echo json_encode(['status' => 'active']);
}
