<?php
require_once __DIR__ . '/../../config.php';
require_once __DIR__ . '/../../engine/Kernel.php';
require_once __DIR__ . '/../../engine/Logger.php';
require_once '../../engine/SudannaPayEngine.php';
$ctx = Kernel::handle(['auth' => 'optional']);
$u = $ctx['user'];
if (!$u) { http_response_code(401); die(json_encode(['error'=>'unauthorized'])); }
$uid = (int)$u['id'];
// إنشاء حساب تلقائياً إذا لم يوجد
$acc = SudannaPayEngine::getAccount($uid);
if (!$acc) SudannaPayEngine::createAccount($uid);
$bal = SudannaPayEngine::getBalance($uid);
$hist = SudannaPayEngine::getHistory($uid, 5);
echo json_encode(['ok'=>true,'balance'=>$bal,'recent'=>$hist], JSON_UNESCAPED_UNICODE);
