<?php
require 'db.php';

header('Content-Type: application/json; charset=utf-8');

if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['id'])) {
    $id = $_POST['id'] ?? null;

    if ($id === null) {
        http_response_code(400);
        echo json_encode(["status" => "error", "message" => "Missing id."]);
        exit;
    }

    $sql = "DELETE FROM SPBU WHERE id = ?";
    $stmt = $pdo->prepare($sql);
    
    if ($stmt->execute([$id])) {
        echo json_encode(["status" => "success", "message" => "Data deleted!"]);
    } else {
        http_response_code(500);
        echo json_encode(["status" => "error", "message" => "Failed to delete data."]);
    }
} else {
    http_response_code(405);
    echo json_encode(["status" => "error", "message" => "Method not allowed."]);
}
?>