<?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']);
    $status = cleanInput($data['status']);

    if (empty($unique_Id) || empty($status)) {
        echo json_encode(['success' => false, 'message' => 'All fields are required.']);
        exit();
    }

    $query = "UPDATE packages SET status = ? WHERE unique_Id = ?";
    $stmt = $conn->prepare($query);

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

        if ($stmt->execute()) {
            echo json_encode(['success' => true, 'message' => 'Status updated successfully.']);
        } else {
            echo json_encode(['success' => false, 'message' => 'Failed to update status.']);
        }

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

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