<?php
require_once '../config.php';

if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
    die("Invalid request");
}

$data = json_decode(file_get_contents("php://input"), true);
if(!$data){ die("Missing JSON"); }

$license    = $data['license'];
$account    = $data['account'];
$ticket     = $data['ticket'];
$symbol     = $data['symbol'];
$type       = $data['type'];
$volume     = $data['volume'];
$open_price = $data['open_price'];
$close_price= $data['close_price'];
$profit     = $data['profit'];
$open_time  = $data['open_time'];
$close_time = $data['close_time'];
$sl         = $data['sl'];
$tp         = $data['tp'];
$comment    = $data['comment'];

$stmt = $conn->prepare("
INSERT INTO fxh_trade_logs 
(license_key, mt5_account, ticket, symbol, type, volume, 
 open_price, close_price, profit, open_time, close_time, sl, tp, comment)
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)
");
$stmt->bind_param("sisssdddddssds",
    $license, $account, $ticket, $symbol, $type, $volume,
    $open_price, $close_price, $profit, $open_time, $close_time, $sl, $tp, $comment
);
$stmt->execute();
$stmt->close();

echo "OK";
