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

export interface StatementResp extends Record<string, unknown> {
  statementId: number;
  agentId: number;
  agentName?: string;
  settleMonth: string;
  statementType: string;
  statementTypeName?: string;
  issueStatus?: string;
  issueStatusName?: string;
  totalCommission?: number;
  totalTax?: number;
  netAmount?: number;
  issuedAt?: string;
}

export interface StatementSearchParam {
  settleMonth?: string;
  statementType?: string;
  issueStatus?: string;
  pageNum?: number;
  pageSize?: number;
}

export interface StatementDetailResp extends StatementResp {
  grossAmount?: number;
  incomeTaxAmount?: number;
  localTaxAmount?: number;
  vatAmount?: number;
  deductionAmount?: number;
  filePath?: string;
  fileFormat?: string;
  issuedBy?: string;
}

export const statementApi = {
  /** 본인 명세서 — 서버측이 토큰 → agentId 강제 필터. */
  list: (params: StatementSearchParam = {}) =>
    unwrap<PageResponse<StatementResp>>(api.get('/api/mobile/me/statements', { params })),

  /** 본인 명세서 단건 — 서버측이 본인 agentId 가 아니면 E403. */
  detail: (statementId: number) =>
    unwrap<StatementDetailResp>(api.get(`/api/mobile/me/statements/${statementId}`)),
};
