<?php

header("Content-Type: application/json; charset=UTF-8");

// Include Database Connection
include 'config.php';

// Fetch data from ShuvoPays table (including id)
$sql = "SELECT id, amount, trnxid, sender, username, Gateway, Method, status, created_at 
        FROM ShuvoPays 
        ORDER BY id DESC";

$result = $conn->query($sql);

$data = [];

if ($result && $result->num_rows > 0) {
    while ($row = $result->fetch_assoc()) {
        $data[] = [
            "id"        => (int)$row["id"],        // <-- integer cast
            "amount"    => (float)$row["amount"],  // <-- optional: numeric
            "trnxid"    => $row["trnxid"],
            "sender"    => $row["sender"],
            "gateway"   => $row["Gateway"],
            "username" => $row["username"],
            "method"    => $row["Method"],
            "status"    => (int)$row["status"],    // <-- status integer
            "created_at"=> $row["created_at"]
        ];
    }
}

// Output JSON
echo json_encode([
    "success" => true,
    "total"   => count($data),
    "data"    => $data
], JSON_PRETTY_PRINT);
?>