import axios from './axios'
import type { BasePaginationData, BaseRespData } from '@/types/api'
import type {
  BatchManageData,
  FactoryOrderNewListData,
  LogListData,
  PickCompleteData,
  PickFailData,
  ProductListData,
  RestockData,
  SearchForm,
  StatusTreeNode,
} from '@/types/api/factoryOrderNew'

// 左侧状态树 - 先保留接口定义，实际数据在前端写死
export function getStatusTreeApi() {
  return axios.get<never, BaseRespData<StatusTreeNode[]>>(
    'factory/orderNew/getStatusTree',
  )
}

export function getFactoryOrderNewListApi(
  data: SearchForm,
  currentPage: number,
  pageSize: number,
  statusCode?: string,
) {
  return axios.post<never, BasePaginationData<FactoryOrderNewListData>>(
    'factory/orderNew/list_page',
    {
      ...data,
      currentPage,
      pageSize,
      statusCode,
    },
  )
}

export function getFactoryOrderNewDetailApi(id: number | string) {
  return axios.get<never, BaseRespData<ProductListData[]>>(
    'factory/orderNew/detail',
    {
      params: { id },
    },
  )
}

export function getFactoryOrderNewLogApi(id: number | string) {
  return axios.get<never, BaseRespData<LogListData[]>>(
    'factory/orderNew/log',
    {
      params: { id },
    },
  )
}

export function confirmOrderApi(ids: (number | string)[]) {
  return axios.post<never, BaseRespData<void>>(
    'factory/orderNew/confirm',
    { ids },
  )
}

export function cancelOrderApi(ids: (number | string)[]) {
  return axios.post<never, BaseRespData<void>>(
    'factory/orderNew/cancel',
    { ids },
  )
}

export function refreshProductInfoApi(ids: (number | string)[]) {
  return axios.post<never, BaseRespData<void>>(
    'factory/orderNew/refreshProductInfo',
    { ids },
  )
}

export function transferOldFlowApi(ids: (number | string)[]) {
  return axios.post<never, BaseRespData<void>>(
    'factory/orderNew/transferOldFlow',
    { ids },
  )
}

export function confirmOrderWithWarehouseApi(
  ids: (number | string)[],
  warehouseId: number | string,
) {
  return axios.post<never, BaseRespData<void>>(
    'factory/orderNew/confirmWithWarehouse',
    { ids, warehouseId },
  )
}

export function cancelOrderWithReasonApi(
  ids: (number | string)[],
  reason: string,
) {
  return axios.post<never, BaseRespData<void>>('factory/orderNew/cancel', {
    ids,
    reason,
  })
}

export function suspendOrderApi(
  ids: (number | string)[],
  reason: string,
  needCustomerHandle: string,
) {
  return axios.post<never, BaseRespData<void>>('factory/orderNew/suspend', {
    ids,
    reason,
    needCustomerHandle,
  })
}

export function cancelSuspendApi(ids: (number | string)[]) {
  return axios.post<never, BaseRespData<void>>(
    'factory/orderNew/cancelSuspend',
    { ids },
  )
}

export function archiveOrderApi(ids: (number | string)[]) {
  return axios.post<never, BaseRespData<void>>('factory/orderNew/archive', {
    ids,
  })
}

export function printPickOrderApi(ids: (number | string)[]) {
  return axios.post<never, BaseRespData<void>>(
    'factory/orderNew/printPickOrder',
    { ids },
  )
}

export function applyReplenishApi(ids: (number | string)[]) {
  return axios.post<never, BaseRespData<void>>(
    'factory/orderNew/applyReplenish',
    { ids },
  )
}

export function batchDeleteApi(ids: (number | string)[]) {
  return axios.post<never, BaseRespData<void>>(
    'factory/orderNew/batchDelete',
    { ids },
  )
}

export function restockCheckApi(id: number | string) {
  return axios.post<never, BaseRespData<void>>(
    'factory/orderNew/restockCheck',
    { id },
  )
}

export function pickCompleteApi(ids: (number | string)[]) {
  return axios.post<never, BaseRespData<PickCompleteData[]>>(
    'factory/orderNew/pickComplete',
    { ids },
  )
}

export function pickFailApi(ids: (number | string)[]) {
  return axios.post<never, BaseRespData<PickFailData[]>>(
    'factory/orderNew/pickFail',
    { ids },
  )
}

export function getRestockListApi(params: {
  stockSku?: string
  styleNo?: string
}) {
  return axios.get<never, BaseRespData<RestockData[]>>(
    'factory/orderNew/restockList',
    { params },
  )
}

export function getBatchManageListApi(
  data: Record<string, unknown>,
  currentPage: number,
  pageSize: number,
) {
  return axios.post<never, BasePaginationData<BatchManageData>>(
    'factory/orderNew/batchManage/list_page',
    { ...data, currentPage, pageSize },
  )
}

export function createOutboundOrderApi(ids: (number | string)[]) {
  return axios.post<never, BaseRespData<void>>(
    'factory/orderNew/createOutboundOrder',
    { ids },
  )
}

