/**
 * 播种墙相关接口
 */
import axios from './axios'
import { BaseRespData } from '@/types/api'
import { PodMakeOrderData } from '@/types/api/podMakeOrder'

// 获取箱子列表
export function getPodBoxListApi(
  url: string,
  factoryNo: number | string,
  warehouseId: number | string,
) {
  return axios.get<never, BaseRespData<PodMakeOrderData[]>>(url, {
    params: { factoryNo, warehouseId },
  })
}

// 打印普通拣货单
export function printNormalPdf(url: string, ids: string) {
  return axios.get<never, BaseRespData<string>>(url, { params: { ids } })
}

// 获取装箱数据
export function getPackingDataApi(
  url: string,
  params: {
    podJomallCnNo?: string
    podJomallUsNo?: string
    podOperationNo?: string
    box?: number | null
    factoryNo?: number
    warehouseId?: number | string
  },
) {
  return axios.get<never, BaseRespData<PodMakeOrderData>>(url, {
    params,
  })
}

// 清空箱子
export function clearBoxApi(
  url: string,
  factoryNo: number,
  box: number | null,
  warehouseId: number | string,
) {
  return axios.get<never, BaseRespData<never>>(url, {
    params: { factoryNo, box, warehouseId },
  })
}

// 清空所有箱子
export function clearAllBoxApi(
  url: string,
  warehouseId: string | number,
  factoryNo: string | number | undefined,
) {
  return axios.get<never, BaseRespData<never>>(url, {
    params: { warehouseId, factoryNo },
  })
}

// 提交打单 cn
export function submitInspectionCnApi(
  url: string,
  data: { id: number; version?: number }[],
  warehouseId: number | string,
  boxIndex?: number | null,
) {
  const params = new URLSearchParams()
  // 先放 warehouseId，再放 boxIndex
  params.set('warehouseId', String(warehouseId))
  if (boxIndex !== undefined && boxIndex !== null) {
    params.set('box', String(boxIndex))
  }

  return axios.post<never, BaseRespData<never>>(`${url}?${params.toString()}`, {
    orderParamList: data,
  })
}

// 提交打单 us
export function submitInspectionUsApi(
  url: string,
  params: {
    orderId?: number
    orderParamList?: { id?: number }[]
  },
  boxIndex: number | null,
  warehouseId: number | string,
) {
  return axios.post<never, BaseRespData<never>>(
    `${url}?box=${boxIndex}&warehouseId=${warehouseId}`,
    params,
  )
}
