import { apiGet, apiPost } from "@/app/lib/clientApi"; import type { AdminTopupPage, AdminTopupRow } from "@/app/lib/types"; // Client over the BFF route handlers (app/api/admin/topup/**), which forward // the bb_admin JWT to mobile-api. A caller without the BO_WALLET module gets a // 4xx from mobile-api and the view renders its not-authorised state (the // RequireModule gate fires first). Reverse is a mutation and is always POST — never a GET. // add-online-topup-ipay88: the member pays online, so there is no approve/reject. /** Paged pending top-up queue. */ export async function getPendingTopups( page: number, pageSize: number, sort: { sortBy?: string; sortDir?: "asc" | "desc" } = {}, ): Promise { const params = new URLSearchParams({ page: String(Math.max(0, page - 1)), size: String(pageSize), }); if (sort.sortBy) { params.set("sortBy", sort.sortBy); if (sort.sortDir) params.set("sortDir", sort.sortDir); } return apiGet(`/api/admin/topup/list?${params.toString()}`); } /** add-topup-reversal: paged completed and reversed top-ups (the Completed view). */ export async function getCompletedTopups( page: number, pageSize: number, sort: { sortBy?: string; sortDir?: "asc" | "desc" } = {}, ): Promise { const params = new URLSearchParams({ page: String(Math.max(0, page - 1)), size: String(pageSize), view: "completed", }); if (sort.sortBy) { params.set("sortBy", sort.sortBy); if (sort.sortDir) params.set("sortDir", sort.sortDir); } return apiGet(`/api/admin/topup/list?${params.toString()}`); } /** add-topup-reversal: reverse a completed top-up with a reason (claws back its rewards). */ export async function reverseTopup(uuid: string, reason: string): Promise { return apiPost("/api/admin/topup/reverse", { uuid, reason }); }