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

if ($_SERVER['REQUEST_METHOD'] === 'GET') {
    $query = "SELECT * FROM mst_metode_bayar WHERE deleted_st = 0 ORDER BY metode_id DESC";
    $result = $conn->query($query);
    
    $data = [];
    if ($result && $result->num_rows > 0) {
        while ($row = $result->fetch_assoc()) {
            // Append base URL to image if not null
            if (!empty($row['qris_gambar'])) {
                $base_url = "http://" . $_SERVER['HTTP_HOST'] . "/api_koneksi/uploads/qris/";
                $row['qris_gambar_url'] = $base_url . $row['qris_gambar'];
            } else {
                $row['qris_gambar_url'] = "";
            }
            $data[] = $row;
        }
        echo json_encode(["status" => "sukses", "pesan" => "Data metode ditemukan", "data" => $data]);
    } else {
        echo json_encode(["status" => "kosong", "pesan" => "Belum ada metode pembayaran", "data" => []]);
    }
} else {
    echo json_encode(["status" => "gagal", "pesan" => "Metode request tidak valid", "data" => []]);
}

$conn->close();
?>
