<?php
require 'config.php';
require_login();

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

$type = $_GET['type'] ?? 'nid';
$cost_api1 = (float)($settings['sc_api1_cost'] ?? 40);
$required = $type === 'nid' ? $cost_api1 : 0;

$stmt = $pdo->prepare("SELECT balance FROM users WHERE id = ?");
$stmt->execute([$_SESSION['user_id']]);
$balance = $stmt->fetchColumn();

echo json_encode([
    'success' => true,
    'current_balance' => (float)$balance,
    'required' => $required,
    'has_enough' => $balance >= $required,
    'message' => $balance >= $required ? 'পর্যাপ্ত ব্যালেন্স আছে' : 'পর্যাপ্ত ব্যালেন্স নেই'
]);
?>