<?php
// File: API_KONEKSI/admin/paket/hapus_paket.php
header('Content-Type: application/json');
include '../../config/koneksi.php';
include '../../config/middleware.php';

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $paket_id = $_POST['paket_id'] ?? '';
    
    // Tangkap data siapa yang menghapus (bisa dikirim dari Android, atau default 'Admin')
    $payload = authenticateJWT();
    $user_id = $payload['user_id'] ?? ''; 

    if (!empty($paket_id)) {
        // REVISI: Tambahkan deleted_at dengan waktu saat ini, dan deleted_by dengan user_id
        $stmt = $conn->prepare("UPDATE mst_paket SET deleted_st = 1, deleted_at = CURRENT_TIMESTAMP, deleted_by = ? WHERE paket_id = ?");
        
        // "si" berarti: String (user_id), Integer (paket_id)
        $stmt->bind_param("ss", $user_id, $paket_id);
        
        if ($stmt->execute()) {
            echo json_encode(["status" => "sukses", "pesan" => "Paket berhasil dihapus", "data" => []]);
        } else {
            echo json_encode(["status" => "gagal", "pesan" => "Gagal menghapus paket", "data" => []]);
        }
        $stmt->close();
    }
}
$conn->close();
?>
