import { request } from '../../boot/axios';
import { Pagination } from '../class';
import {
  AddOrEditFormData,
  BatchAddFormData,
  BinListSearchEntity,
  BinSizeAddOrEditForm,
  BinSizeSearchEntity,
  ContainerAddOrEditForm,
  ContainerSearchEntity
} from './model/bin';

const pathBinName = 'bin/';
const pathBinSizeName = 'binSize/';
const pathContainerName = 'container/';

class BinApi {
  // 库位 分页
  getPage = (val?: Pagination<BinListSearchEntity>) => {
    return request.postForPage(`${pathBinName}page`, val);
  };
  // 库位 新增
  add = (val?: AddOrEditFormData) => {
    return request.post(`${pathBinName}add`, val);
  };
  // 库位 修改
  edit = (val?: AddOrEditFormData) => {
    return request.put(`${pathBinName}edit`, val);
  };
  // 库位 删除
  remove = (val: string) => {
    return request.delete(`${pathBinName}remove/${val}`);
  };
  batchAdd = (val?: BatchAddFormData) => {
    return request.post(`${pathBinName}batchAdd`, val);
  };
  ///
  // 联动根据库区 获取库位集合方法
  // @val1 = 库区ID
  // @val2 = 搜索参数
  ///
  getBinList = (val1: string, val2: string) => {
    return request.post('bin/list', {
      areaId: val1,
      binName: val2
    });
  };

  ///
  // 联动根据工厂 获取库位集合方法
  // @warehouseId = 工厂ID
  // @binName = 搜索参数
  ///
  getBinListByWarehouseId = (warehouseId: string, binName: string) => {
    return request.post('bin/list', {
      warehouseId: warehouseId,
      binName: binName
    });
  };

  ///
  // 根据工厂ID 移动类型 查询用于调拨的库位集合
  // @moveType = 移动类型
  // @startWarehouseId = 开始工厂id
  // @combinationName = 模糊搜索条件
  ///
  getTargetBin = (
    startWarehouseId: string,
    moveType: string,
    combinationName: string
  ) => {
    return request.post(`${pathBinName}getTargetBin`, {
      startWarehouseId: startWarehouseId,
      moveType: moveType,
      combinationName: combinationName
    });
  };
}
const binApi = new BinApi();

class BinSizeApi {
  // 库位尺寸管理 分页
  getPage = (val?: Pagination<BinSizeSearchEntity>) => {
    return request.postForPage(`${pathBinSizeName}page`, val);
  };
  // 库位尺寸管理 新增
  add = (val?: BinSizeAddOrEditForm) => {
    return request.post(`${pathBinSizeName}add`, val);
  };
  // 库位尺寸管理 修改
  edit = (val?: BinSizeAddOrEditForm) => {
    return request.put(`${pathBinSizeName}edit`, val);
  };
  // 库位尺寸管理 删除
  remove = (val: string) => {
    return request.delete(`${pathBinSizeName}remove/${val}`);
  };
  // 库位尺寸管理 查询下拉接口
  getBinSizeList = (val: any) => {
    return request.post(`${pathBinSizeName}list`, { binSize: val });
  };
}
const binSizeApi = new BinSizeApi();

class ContainerApi {
  getPage = (val?: Pagination<ContainerSearchEntity>) => {
    return request.postForPage(`${pathContainerName}page`, val);
  };

  addOrEdit = (val?: ContainerAddOrEditForm) => {
    return request.post(`${pathContainerName}saveOrUpdate`, val);
  };

  add = (val?: ContainerAddOrEditForm) => {
    return request.post(`${pathContainerName}add`, val);
  };

  edit = (val?: ContainerAddOrEditForm) => {
    return request.post(`${pathContainerName}edit`, val);
  };

  getContainerList = (val?: any) => {
    return request.post(`${pathContainerName}list`, { containerName: val });
  };

  remove = (val: string) => {
    return request.delete(`${pathContainerName}delete/` + val);
  };
}
const containerApi = new ContainerApi();

export { binApi, binSizeApi, containerApi };
