<?php
require_once "../config/db.php";
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['request_Id'])) {
    $request_Id = $_POST['request_Id'];
    $query = "DELETE FROM ship WHERE request_Id = ?";
    $stmt = $conn->prepare($query);

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

        // Execute the query
        if ($stmt->execute()) {
            if ($stmt->affected_rows > 0) {
                echo json_encode([
                    'status' => 'success',
                    'message' => 'Shipping record deleted successfully.'
                ]);
            } else {
                echo json_encode([
                    'status' => 'error',
                    'message' => 'No record found with the provided transaction ID.'
                ]);
            }
        } else {
            echo json_encode([
                'status' => 'error',
                'message' => 'Failed to execute delete query.'
            ]);
        }

        // Close the statement
        $stmt->close();
    } else {
        echo json_encode([
            'status' => 'error',
            'message' => 'Failed to prepare delete query.'
        ]);
    }

    // Close the database connection
    $conn->close();
} else {
    echo json_encode([
        'status' => 'error',
        'message' => 'Invalid request.'
    ]);
}
