import { apiGet, apiPost, apiPut } from "@/app/lib/clientApi"; import type { AdminWithdrawalPage, AdminWithdrawalRow, WithdrawalConfig, WithdrawalConfigInput, } from "@/app/lib/types"; // Client over the BFF route handlers (app/api/admin/withdrawal/**), 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). Approve/reject are mutations and are always // POST — never a GET. Mirrors adminTopups.ts. /** Paged withdrawal queue. `status` is a status code or `"ALL"`; `member` matches code or name. `cycle` is `"NONE"` (unscheduled) or an ISO * date-time exactly as returned by `nextCutoff`/`payoutCycleCutoff`; omitted entirely * when not supplied (no filter). */ export async function getPendingWithdrawals( page: number, pageSize: number, filters: { cycle?: string; status?: string; member?: string } = {}, sort: { sortBy?: string; sortDir?: "asc" | "desc" } = {}, ): Promise { const params = new URLSearchParams({ page: String(Math.max(0, page - 1)), size: String(pageSize), }); for (const [key, value] of Object.entries(filters)) { if (value) params.set(key, value); } if (sort.sortBy) { params.set("sortBy", sort.sortBy); if (sort.sortDir) params.set("sortDir", sort.sortDir); } return apiGet(`/api/admin/withdrawal/list?${params.toString()}`); } /** Current min/max/increment/fee + weekly cut-off settings (BABYBOO-13, Task 4). */ export async function getWithdrawalConfig(): Promise { return apiGet("/api/admin/withdrawal/config"); } /** Saves the settings — a mutation, always PUT. Optional fields are sent as `null` * when blank (never `0` or `""`); the server stays authoritative on validation. */ export async function updateWithdrawalConfig(input: WithdrawalConfigInput): Promise { return apiPut("/api/admin/withdrawal/config", input); } /** Single-stage approval: disburses the net amount (stub adapter) and records the approver. */ export async function approveWithdrawal(uuid: string): Promise { return apiPost("/api/admin/withdrawal/approve", { uuid }); } /** Rejection with a reason (reverses the reservation). */ export async function rejectWithdrawal(uuid: string, reason: string): Promise { return apiPost("/api/admin/withdrawal/reject", { uuid, reason }); }