import axios from './axios'
import type { BasePaginationData } from '@/types/api'
import type { operateOrderListData } from '@/types/api/factoryOrderNew'

function normalizePodOrderQueryPayload(
  data: Record<string, unknown>,
): Record<string, unknown> {
  const { receiverCountry, ...rest } = data
  if (!Array.isArray(receiverCountry)) {
    return data
  }
  return {
    ...rest,
    ...(receiverCountry.length
      ? { receiverCountry: receiverCountry.join(',') }
      : {}),
  }
}

export function getCancelOrderProcessListApi(
  data: Record<string, unknown>,
  currentPage: number,
  pageSize: number,
) {
  const body = normalizePodOrderQueryPayload({ ...data })
  return axios.post<never, BasePaginationData<operateOrderListData>>(
    'factory/podOrderOperation/list_page',
    { ...body, status: 'PENDING_SCHEDULE', currentPage, pageSize },
  )
}
