import api, { PageResponse, unwrap } from './request';

export interface PaymentResp {
  paymentId: number;
  settleId: number;
  agentId: number;
  agentName: string;
  bankCode?: string;
  bankName?: string;
  accountNo?: string;
  payAmount: number;
  payDate?: string;
  payStatus: string;
  payStatusName?: string;
  failReason?: string;
  settleMonth: string;
  transferFileId?: number;
}

export interface TransferFileResp {
  fileId: number;
  fileName: string;
  paymentCount: number;
  totalAmount: number;
}

export const paymentApi = {
  list: (p: { settleMonth?: string; agentId?: number; status?: string; pageNum?: number; pageSize?: number }) =>
    unwrap<PageResponse<PaymentResp>>(api.get('/api/payments', { params: p })),
  updateStatus: (paymentId: number, status: string, failReason?: string) =>
    unwrap<void>(api.put(`/api/payments/${paymentId}/status`, { status, failReason })),
  generateTransferFile: (settleMonth: string, bankCode: string) =>
    unwrap<TransferFileResp>(api.post('/api/payments/transfer-file', null, { params: { settleMonth, bankCode } })),
};
