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

export interface LedgerResp {
  ledgerId: number;
  agentId: number;
  agentName: string;
  orgName?: string;
  policyNo?: string;
  contractorName?: string;
  contractDate?: string;
  companyCode?: string;
  companyName?: string;
  productCode?: string;
  productName?: string;
  insuranceType?: string;
  premium?: number;
  companyRate?: number;
  companyAmount?: number;
  payoutRate?: number;
  agentAmount?: number;
  taxAmount?: number;
  reconcileStatus?: string;
  settleMonth: string;
  status: string;
  statusName?: string;
}

export interface LedgerSearchParam {
  pageNum?: number;
  pageSize?: number;
  settleMonth?: string;
  agentId?: number;
  orgId?: number;
  companyCode?: string;
  insuranceType?: string;
  policyNo?: string;
  searchKeyword?: string;
}

export const ledgerApi = {
  recruit: (p: LedgerSearchParam) =>
    unwrap<PageResponse<LedgerResp>>(api.get('/api/ledger/recruit', { params: p })),
  maintain: (p: LedgerSearchParam) =>
    unwrap<PageResponse<LedgerResp>>(api.get('/api/ledger/maintain', { params: p })),
  exception: (p: LedgerSearchParam) =>
    unwrap<PageResponse<unknown>>(api.get('/api/ledger/exception', { params: p })),
};
