import { request } from '../request';

// 定义 API URL 常量
const BASE_URL = 'http://localhost:58926/api';

// 声明接口 URL 变量
const GET_CODELIST = `${BASE_URL}/System/GetCodeList`;
const GET_CELL = `${BASE_URL}/ManageTask/GetCELL`;
const ADD_ManageTask = `${BASE_URL}/ManageTask/CreateManageTask`;
const ADD_ManageTaskOut = `${BASE_URL}/ManageTask/CreateManageTaskOut`;
const ADD_ManageTaskInv = `${BASE_URL}/ManageTask/CreateInvManageTask`;
const InvManageTaskToWCS = `${BASE_URL}/ManageTask/InvManageTaskToWCS`;
const GET_FinishManageTask = `${BASE_URL}/ManageTask/GetFinishManageTask`;
const GET_FinishInvManageTask = `${BASE_URL}/ManageTask/GetFinishInvManageTask`;
const GET_InvTaskDetailItem = `${BASE_URL}/ManageTask/GetInvTaskDetailItem`;
const GET_InvManageTask = `${BASE_URL}/ManageTask/GetInvManageTask`;
const GET_TodoWorkManageTask = `${BASE_URL}/ManageTask/GetTodoWorkManageTask`;
const GET_TaskDetailItem = `${BASE_URL}/ManageTask/GetTaskDetailItem`;
const GET_LybRemainderNumber = `${BASE_URL}/ManageTask/GetLybRemainderNumber`;
const GET_SystemCode = `${BASE_URL}/ManageTask/GetSystemCode`;
const GET_Inventory = `${BASE_URL}/ManageTask/GetInventory`;
const GET_InventoryOutAdd = `${BASE_URL}/ManageTask/GetInventoryAddOut`;
const ADD_ManageTaskToWCS = `${BASE_URL}/ManageTask/ManageTaskToWCS`;
const GET_AllCell = `${BASE_URL}/ManageTask/GetAllCell`;
const GET_CellInfo = `${BASE_URL}/ManageTask/GetCellInfo`;
const GetAllInv = `${BASE_URL}/ManageTask/GetAllInv`;

// 获取储位
export function fetchGetAllCell() {
  return request<Api.InventoryTask.WhCell_ResponseResult>({
    url: GET_AllCell,
    method: 'post'
  });
}
// 获取储位
export function fetchGetAllInv() {
  return request<Api.InventoryTask.WhCellInfo_ResponseResult>({
    url: GetAllInv,
    method: 'post'
  });
}
// 获取储位详情
export function fetchGetCellInfo(params?: Api.InventoryTask.WhCellInfoRequest) {
  return request<Api.InventoryTask.WhCellInfo_ResponseResult>({
    url: GET_CellInfo,
    method: 'post',
    data: params
  });
}
/** get code list */
export function fetchGetCodeList(params?: Api.SystemManage.CodesSearchParams) {
  return request<Api.SystemManage.CodesList>({
    url: GET_CODELIST,
    method: 'post',
    data: params
  });
}

/** 获取库存信息 */
export function fetchGetInventoryOutAdd(params?: Api.Exploitation.InventorySearchParams) {
  return request<Api.Exploitation.InventoryList>({
    url: GET_InventoryOutAdd,
    method: 'post',
    data: params
  });
}

/** 获取库存信息 */
export function fetchGetInventory(params?: Api.Exploitation.InventorySearchParams) {
  return request<Api.Exploitation.InventoryList>({
    url: GET_Inventory,
    method: 'post',
    data: params
  });
}

/** 获取储位对应的上层编码 */
export function fetchGetSystemCode(params: { TaskNo: string }) {
  return request<Api.PlanManage.SystemCode>({
    url: GET_SystemCode,
    method: 'post',
    data: params
  });
}

/** 获取分配到的储位 */
export function fetchGetCell() {
  return request<Api.PlanManage.GetCell_ResponseResult>({
    url: GET_CELL,
    method: 'post'
  });
}
// 添加任务
export function fetchAddManageTaskOut(params?: { [key: string]: number }) {
  return request<Api.PlanManage.GetCell_ResponseResult>({
    url: ADD_ManageTaskOut,
    method: 'post',
    data: params
  });
}
// 添加盘库任务
export function fetchAddManageTaskInv() {
  return request<Api.PlanManage.GetCell_ResponseResult>({
    url: ADD_ManageTaskInv,
    method: 'post'
  });
}
/** 添加任务 */
// export function fetchAddManageTask(params?: Api.PlanManage.OrdersData) {
//   return request<Api.PlanManage.GetCell_ResponseResult>({
//     url: ADD_ManageTask,
//     method: 'post',
//     data: params
//   });
// }
/** 添加任务 */
export function fetchAddManageTask(params: { ordersData: Api.PlanManage.OrdersData; isImmediate: boolean }) {
  return request<Api.PlanManage.GetCell_ResponseResult>({
    url: ADD_ManageTask,
    method: 'post',
    data: params
  });
}

/** 获取未完成的盘点任务 */
export function fetchGetInvManageTask(params?: Api.InventoryTask.InventorySearchParams) {
  return request<Api.InventoryTask.Inventory_ResponseResult>({
    url: GET_InvManageTask,
    method: 'post',
    data: params
  });
}

/** 获取已完成的盘点任务 */
export function fetchGetFinishInvManageTask(params?: Api.InventoryTask.InventorySearchParams) {
  return request<Api.InventoryTask.InventoryList>({
    url: GET_FinishInvManageTask,
    method: 'post',
    data: params
  });
}

/** 获取已完成任务 */
export function fetchGetFinishManageTask(params?: Api.PlanManage.TaskDetailsSearchParams) {
  return request<Api.PlanManage.TaskDetailsList>({
    url: GET_FinishManageTask,
    method: 'post',
    data: params
  });
}

/** 获取待执行任务 */
export function fetchGetTodoWorkManageTask(params?: Api.PlanManage.TaskDetailsSearchParams) {
  return request<Api.PlanManage.GetCell_ResponseResult>({
    url: GET_TodoWorkManageTask,
    method: 'post',
    data: params
  });
}

/** 获取任务的下级明细 */
export function fetchGetTaskDetailItem(params: { TaskNo: string }) {
  return request<Api.PlanManage.TaskDetailItem_List>({
    url: GET_TaskDetailItem,
    method: 'post',
    data: params
  });
}
/** 获取盘库任务的下级明细 */
export function fetchGetInvTaskDetailItem(params: { TaskNo: string }) {
  return request<Api.InventoryTask.InventoryItem_ResponseResult>({
    url: GET_InvTaskDetailItem,
    method: 'post',
    data: params
  });
}

/** 获取当前履约表剩余入库数量 */
export function fetchGetLybRemainderNumber(params: { TaskNo: string }) {
  return request<Api.PlanManage.LybRemainderNumber>({
    url: GET_LybRemainderNumber,
    method: 'post',
    data: params
  });
}

/** 执行任务 */
export function fetchAddManageTaskToWCS(params?: Api.PlanManage.ManageTaskToWCSRequest) {
  return request<Api.PlanManage.GetCell_ResponseResult>({
    url: ADD_ManageTaskToWCS,
    method: 'post',
    data: params
  });
}
/** 执行任务 */
export function fetchAddInvManageTaskToWCS(params?: Api.InventoryTask.Inventory) {
  return request<Api.PlanManage.GetCell_ResponseResult>({
    url: InvManageTaskToWCS,
    method: 'post',
    data: params
  });
}
