<?php
include "../includes/db.php";
include "../includes/auth.php";
header("Content-Type: application/json");

if (isset($_POST['id'])) {
    $id = (int)$_POST['id'];
    $conn->query("DELETE FROM messages WHERE id=$id");
    if ($conn->affected_rows > 0) {
        echo json_encode(['status' => 'success']);
    } else {
        echo json_encode(['status' => 'error', 'message' => 'Message not found or already deleted.']);
    }
} else {
    http_response_code(400);
    echo json_encode(['status' => 'error', 'message' => 'Missing id.']);
}
