<?php
error_reporting(0);
header('Content-Type: application/json');
header("Access-Control-Allow-Origin: *");
require_once '../config/db.php';

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

$wallet = $input['wallet'] ?? '';
$position = $input['position'] ?? '';
$amount = $input['amount'] ?? 0;
$pnl_amount = $input['pnl_amount'] ?? 0;
$day_type = $input['day_type'] ?? '';
$rate = $input['rate'] ?? 0;

if (!$wallet) {
    echo json_encode(['status' => 'error', 'message' => 'Wallet required']);
    exit;
}

$query = "INSERT INTO trade_logs (wallet, position, amount, pnl_amount, day_type, rate) 
          VALUES ('$wallet', '$position', '$amount', '$pnl_amount', '$day_type', '$rate')";

if (mysqli_query($conn, $query)) {
    echo json_encode(['status' => 'success']);
} else {
    echo json_encode(['status' => 'error', 'message' => mysqli_error($conn)]);
}
?>