<?php
require 'db.php';

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

if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
    http_response_code(405);
    echo json_encode(['status' => 'error', 'message' => 'Method not allowed.']);
    exit;
}

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

$sql = "DELETE FROM tb_parsil WHERE id = ?";
$stmt = $pdo->prepare($sql);

if ($stmt->execute([(int)$id])) {
    echo json_encode(['status' => 'success', 'message' => 'Parsil deleted.']);
} else {
    http_response_code(500);
    echo json_encode(['status' => 'error', 'message' => 'Failed to delete parsil.']);
}
