<?php
session_start();
require 'includes/db.php';

// Check authentication
if (!isset($_SESSION['user_id'])) {
    http_response_code(401); // Unauthorized
    echo json_encode(['error' => 'Unauthorized']);
    exit;
}

$user_id = $_SESSION['user_id'];

$stmt = $pdo->prepare("SELECT id, username, name, balance, currency, merchant_key, secret_key, trade_code, payin_fee, payout_fee FROM users WHERE id = ?");
$stmt->execute([$user_id]);
$user = $stmt->fetch(PDO::FETCH_ASSOC);

if (!$user) {
    http_response_code(404);
    echo json_encode(['error' => 'User not found']);
    exit;
}

// Send JSON response
header('Content-Type: application/json');
echo json_encode($user);
