import { apiGet, apiPost } from "@/app/lib/clientApi"; import type { AdminRefundDetail, AdminRefundPage, AdminRefundRequest, AdminRefundEligibility, RaiseRefundBody, ShipmentCancelQuote, CancelShipmentBody, } from "@/app/lib/types"; /** Refund filter options for listRefunds. */ export interface RefundFilters { status?: string; requestNo?: string; invoiceNo?: string; member?: string; from?: string; to?: string; page?: number; size?: number; sortBy?: string; sortDir?: "asc" | "desc"; } /** Paged refund request list. */ export async function listRefunds(filters: RefundFilters = {}): Promise { const params = new URLSearchParams(); // Only set non-empty values if (filters.status) params.set("status", filters.status); if (filters.requestNo) params.set("requestNo", filters.requestNo); if (filters.invoiceNo) params.set("invoiceNo", filters.invoiceNo); if (filters.member) params.set("member", filters.member); if (filters.from) params.set("from", filters.from); if (filters.to) params.set("to", filters.to); if (filters.sortBy) { params.set("sortBy", filters.sortBy); if (filters.sortDir) params.set("sortDir", filters.sortDir); } params.set("page", String(filters.page ?? 0)); params.set("size", String(filters.size ?? 20)); return apiGet(`/api/refunds?${params.toString()}`); } /** Enriched refund detail. */ export async function getRefund(uuid: string): Promise { return apiGet(`/api/refunds/${encodeURIComponent(uuid)}`); } /** Approve a refund request (mutation — POST only). */ export async function approveRefund(uuid: string, options?: { note?: string }): Promise { const body: Record = {}; if (options?.note) body.note = options.note; return apiPost(`/api/refunds/${encodeURIComponent(uuid)}/approve`, body); } /** Reject a refund request with a reason (mutation — POST only). */ export async function rejectRefund(uuid: string, reason: string): Promise { return apiPost(`/api/refunds/${encodeURIComponent(uuid)}/reject`, { reason }); } /** Re-send the refund notification email (mutation — POST only). */ export async function retryRefundEmail(uuid: string): Promise { return apiPost(`/api/refunds/${encodeURIComponent(uuid)}/retry-email`, {}); } /** Whether an admin may refund this order (read only). */ export async function getRefundEligibility(orderUuid: string): Promise { return apiGet(`/api/refunds/eligibility/${encodeURIComponent(orderUuid)}`); } /** Raise and apply an admin refund (mutation — POST only). */ export async function raiseRefund(body: RaiseRefundBody): Promise { return apiPost("/api/refunds/raise", body); } // --- Shipment cancel (add-shipment-cancel) --- /** GET a shipment cancel quote (side-effect free). */ export async function getShipmentCancelQuote(doUuid: string): Promise { return apiGet(`/api/refunds/cancelShipment/${encodeURIComponent(doUuid)}`); } /** Cancel a shipment (mutation — POST only). */ export async function cancelShipment(doUuid: string, body: CancelShipmentBody): Promise { return apiPost(`/api/refunds/cancelShipment/${encodeURIComponent(doUuid)}`, body); } /** babyboo-30-refund-request-redesign: BFF path for one refund photo streamed in the drawer. */ export const adminRefundPhotoUrl = (uuid: string, index: number) => `/api/refunds/${encodeURIComponent(uuid)}/photos/${index}`;