<?php
require_once __DIR__.'/../../config.php';
require_once __DIR__ . '/../../engine/Kernel.php';
require_once __DIR__.'/../../engine/Logger.php';
$ctx = Kernel::handle(['auth' => true]);
$u   = $ctx['user'];
try {
    $st = db()->prepare("SELECT id,name,phone,email,plan_key,subscription_tier,created_at FROM users WHERE id=? LIMIT 1");
    $st->execute([(int)$u['id']]);
    $user = $st->fetch();
    echo json_encode(['ok'=>true,'data'=>$user], JSON_UNESCAPED_UNICODE);
} catch(\Throwable $e){http_response_code(500);echo json_encode(['error' => 'server_error', 'message' => 'خطأ مؤقت — حاول مرة أخرى'], JSON_UNESCAPED_UNICODE);}
