<?php
include 'conexao.php';

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

$peca = $data['peca'];
$n = $data['n'];
$l = $data['l'];
$s = $data['s'];
$o = $data['o'];

try {
    $stmt = $pdo->prepare("UPDATE tabuleiro SET peca = :peca WHERE n = :n AND l = :l AND s = :s AND o = :o");
    $stmt->bindParam(':peca', $peca);
    $stmt->bindParam(':n', $n);
    $stmt->bindParam(':l', $l);
    $stmt->bindParam(':s', $s);
    $stmt->bindParam(':o', $o);
    $stmt->execute();

    echo json_encode(array("success" => true, "message" => "Peça movida com sucesso."));
} catch (PDOException $e) {
    echo json_encode(array("success" => false, "message" => "Erro ao mover peça: " . $e->getMessage()));
}
?>
