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

export interface ExternalCallLogResp extends Record<string, unknown> {
  logId: number;
  callType: string;            // BANK / MESSAGE
  adapterClass: string;        // Mock / Kftc / Toast
  methodName: string;          // requestTransfer / queryStatus / send
  targetRefType?: string;
  targetRefId?: number;
  requestSummary?: string;
  responseSummary?: string;
  resultCode?: string;
  resultMessage?: string;
  success: boolean;
  durationMs?: number;
  errorClass?: string;
  errorMessage?: string;
  calledAt: string;
  createdBy?: number;
}

export interface ExternalCallLogSearchParam {
  callType?: string;
  methodName?: string;
  success?: boolean;
  targetRefType?: string;
  targetRefId?: number;
  startDate?: string;
  endDate?: string;
  pageNum?: number;
  pageSize?: number;
}

export const externalCallLogApi = {
  list: (params?: ExternalCallLogSearchParam) =>
    unwrap<{ list: ExternalCallLogResp[]; total: number }>(
      api.get('/api/external-call-logs', { params })
    ),
  detail: (id: number) =>
    unwrap<ExternalCallLogResp>(api.get(`/api/external-call-logs/${id}`)),
};
