<?php
require '../config/db.php';
require '../config/function/function.php';

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $data = json_decode(file_get_contents('php://input'), true);
    $unique_Id = cleanInput($data['unique_Id']);

    if (empty($unique_Id)) {
        echo json_encode(['success' => false, 'message' => 'Unique ID is required.']);
        exit();
    }

    $query = "DELETE FROM packages WHERE unique_Id = ?";
    $stmt = $conn->prepare($query);

    if ($stmt) {
        $stmt->bind_param("s", $unique_Id);

        if ($stmt->execute()) {
            echo json_encode(['success' => true, 'message' => 'User deleted successfully.']);
        } else {
            echo json_encode(['success' => false, 'message' => 'Failed to delete user.']);
        }

        $stmt->close();
    } else {
        echo json_encode(['success' => false, 'message' => 'Database error.']);
    }

    $conn->close();
} else {
    echo json_encode(['success' => false, 'message' => 'Invalid request method.']);
}
?>