<?php
// File: admin/metode/hapus_metode.php
header('Content-Type: application/json');
include '../../config/koneksi.php';

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $metode_id = isset($_POST['metode_id']) ? $_POST['metode_id'] : '';
    $admin_name = isset($_POST['admin_name']) ? $_POST['admin_name'] : 'Admin';

    if (empty($metode_id)) {
        echo json_encode(["status" => "gagal", "pesan" => "ID Metode tidak valid", "data" => []]);
        exit;
    }

    $query = "UPDATE mst_metode_bayar SET deleted_st = 1, deleted_by = ?, deleted_at = CURRENT_TIMESTAMP WHERE metode_id = ?";
    $stmt = $conn->prepare($query);
    $stmt->bind_param("ss", $admin_name, $metode_id);

    if ($stmt->execute()) {
        echo json_encode(["status" => "sukses", "pesan" => "Metode pembayaran berhasil dihapus", "data" => []]);
    } else {
        echo json_encode(["status" => "gagal", "pesan" => "Gagal menghapus metode: " . $stmt->error, "data" => []]);
    }

    $stmt->close();
} else {
    echo json_encode(["status" => "gagal", "pesan" => "Metode tidak diizinkan", "data" => []]);
}

$conn->close();
?>
