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

export interface WithholdingTaxReportResp extends Record<string, unknown> {
  reportId: number;
  agentId: number;
  agentName?: string;
  agentCode?: string;
  orgName?: string;
  reportYear: number;
  reportQuarter: number;
  totalIncome: number;
  withholdingTax: number;
  status?: string;
  statusName?: string;
  reportedAt?: string;
  createdAt?: string;
  updatedAt?: string;
}

export interface WithholdingTaxSearchParam {
  reportYear?: number;
  reportQuarter?: number;
  agentId?: number;
  agentName?: string;
  status?: string;
  pageNum?: number;
  pageSize?: number;
}

export interface WithholdingTaxRegenerateReq {
  reportYear: number;
  reportQuarter: number;
}

export interface WithholdingTaxReportCompleteReq {
  ids: number[];
}

export const withholdingTaxApi = {
  list: (params?: WithholdingTaxSearchParam) =>
    unwrap<{ list: WithholdingTaxReportResp[]; total: number }>(
      api.get('/api/withholding-tax-reports', { params })
    ),
  detail: (id: number) =>
    unwrap<WithholdingTaxReportResp>(api.get(`/api/withholding-tax-reports/${id}`)),
  regenerate: (req: WithholdingTaxRegenerateReq) =>
    unwrap<void>(api.post('/api/withholding-tax-reports/regenerate', req)),
  complete: (req: WithholdingTaxReportCompleteReq) =>
    unwrap<void>(api.put('/api/withholding-tax-reports/complete', req)),
};
