import { requestClient } from '#/api/request';

const prefix = 'order/';

export async function simulatePayApi(data: {
  order_id: number;
  order_type: 'product' | 'register';
}) {
  return requestClient.post<any>(`${prefix}simulate-pay`, data);
}

export async function getOrderTraceApi(params: {
  order_id: number;
  scene: 'product' | 'register';
}) {
  return requestClient.get<any>(`${prefix}trace`, { params });
}

export async function getOrderLedgerDetailApi(params: {
  order_id: number;
  order_type: number;
  scope?: 'all' | 'platform' | 'store';
}) {
  return requestClient.get<any>(`${prefix}ledger-detail`, { params });
}

export async function getOrderReconciliationDetailApi(params: {
  product_order_id: number;
}) {
  return requestClient.get<any>(`${prefix}reconciliation-detail`, { params });
}

export async function getChinaErpSyncLogsApi(params: {
  order_id: number;
  page?: number;
  pageSize?: number;
}) {
  return requestClient.get<{
    list: Array<{
      content: string;
      content_preview: string;
      created_at: string;
      id: number;
      is_success: number;
      order_id: number;
    }>;
    page: number;
    pageSize: number;
    total: number;
  }>(`${prefix}china-erp-sync-logs`, { params });
}

export async function syncChinaOrderToErpApi(data: { order_id: number }) {
  return requestClient.post<any>(`${prefix}sync-china-erp`, data);
}

export async function accrueSalespersonCommissionApi(data: { order_id: number }) {
  return requestClient.post<any>('salesperson/accrue-order', data);
}
