<?php
header('Content-Type: application/json');
require_once '../includes/auth.php';

if (!$auth->isLoggedIn()) {
    http_response_code(401);
    echo json_encode(['success' => false, 'message' => 'Unauthorized']);
    exit();
}

$user_id = $auth->getCurrentUserId();
$user_data = $auth->getCurrentUser();

if (!$user_data) {
    http_response_code(404);
    echo json_encode(['success' => false, 'message' => 'User not found']);
    exit();
}

echo json_encode([
    'success' => true,
    'data' => [
        'balance' => number_format($user_data['balance'], 2),
        'profit_balance' => number_format($user_data['profit_balance'], 2),
        'referral_balance' => number_format($user_data['referral_balance'], 2),
        'total_deposit' => number_format($user_data['total_deposit'], 2),
        'total_withdrawal' => number_format($user_data['total_withdrawal'], 2)
    ]
]);
?>
