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

export interface AgentAnnualIncomeResp extends Record<string, unknown> {
  incomeId: number;
  agentId: number;
  agentName?: string;
  agentCode?: string;
  orgName?: string;
  settleYear: number;
  totalCommission: number;
  totalTaxWithheld: number;
  businessIncome: number;
  status?: string;
  statusName?: string;
  createdAt?: string;
  updatedAt?: string;
}

export interface AgentAnnualIncomeSaveReq {
  agentId: number;
  settleYear: number;
  totalCommission: number;
  totalTaxWithheld: number;
  businessIncome: number;
}

export interface AgentAnnualIncomeSearchParam {
  settleYear?: number;
  agentId?: number;
  agentName?: string;
  pageNum?: number;
  pageSize?: number;
}

export const incomeApi = {
  list: (params?: AgentAnnualIncomeSearchParam) =>
    unwrap<{ list: AgentAnnualIncomeResp[]; total: number }>(
      api.get('/api/agent-annual-incomes', { params })
    ),
  detail: (id: number) =>
    unwrap<AgentAnnualIncomeResp>(api.get(`/api/agent-annual-incomes/${id}`)),
  regenerate: (year: number) =>
    unwrap<void>(api.post(`/api/agent-annual-incomes/regenerate`, null, { params: { year } })),
};
