<?php
session_start();

header("Access-Control-Allow-Origin: https://enerliths.com");
header("Access-Control-Allow-Credentials: true");
header("Access-Control-Allow-Headers: Content-Type");
header("Access-Control-Allow-Methods: POST, OPTIONS");
header("Content-Type: application/json");

if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
    http_response_code(200);
    exit();
}
require_once "../config/db.php";

$data = json_decode(file_get_contents("php://input"), true);

$user_id = $data["user_id"];
$amount = floatval($data["amount"]);

if ($amount < 5) {
    http_response_code(422);
    echo json_encode(["success" => false, "error" => "Minimum deposit is $5"]);
    exit;
}

$wallet = "TJAbqzvjE1bbs8GLUtxfe7P4troEgMT7UZ"; // your USDT TRC20 wallet

$stmt = $conn->prepare("
INSERT INTO crypto_deposits
(user_id,amount,wallet_address,status)
VALUES (?,?,?,'pending')
");

$stmt->bind_param("ids",$user_id,$amount,$wallet);
$stmt->execute();

$deposit_id = $stmt->insert_id;

echo json_encode([
    "success"=>true,
    "wallet"=>$wallet,
    "deposit_id"=>$deposit_id
]);
