import { request } from '../../boot/axios';
import { Pagination } from '../class';
import {
  StockDnSearchEntity,
  StockDetailSearchEntity,
  StockMaterialViewSearchEntity,
  StockPutawayEntity,
  StockSearchEntity,
  DeliveryStockEntity
} from './model/stock';

import { DnStockSearchEntity } from '../outbound/model/outbound';
const pathName = 'stock';
const stockPathName = 'stockMaterialView';
const stockMaterialPathName = 'stockMaterial';

class StockApi {
  getPage = (val: Pagination<StockSearchEntity>) => {
    return request.postForPage('stock/page', val);
  };
  getOne = (val: DnStockSearchEntity) => {
    return request.post('stock/getOne', val);
  };
  updateSafetyStock = (val1?: any, val2?: any) => {
    return request.post(`${pathName}/updateSafetyStock/${val1}/${val2}`);
  };
  // 获取状态字典
  getDnStatus = () => {
    return request.get('/dict/type/dn_status');
  };
  //  获取包装单位
  gePackUnitMap = () => {
    return request.get('materialsunit/getUnitList/1/');
  };
  // 获取记账单位
  getRecordUnitMap = () => {
    return request.get('materialsunit/getUnitList/2/');
  };
  // 获取客户列表
  getCustomerList = () => {
    return request.get('customer/customer-list');
  };
  getStock = (val?: any) => {
    return request.post(`${pathName}getStock/${val}`, {});
  };
  getStockPage = (val?: any) => {
    return request.post('stock/getStockPage/', val);
  };
  // 获取库存 集合
  getStockMaterialsViewList = (val?: any) => {
    return request.post(`${stockPathName}/list`, val);
  };
  // 出库 获取库存 集合
  getStockMaterialPage = (val: Pagination<StockMaterialViewSearchEntity>) => {
    return request.postForPage('dn/pageForAddDn', val);
  };
  // 调拨 获取库存 集合
  getStockMaterialTfPage = (val: Pagination<StockMaterialViewSearchEntity>) => {
    return request.postForPage('dn/pageForAddTf', val);
  };
  // 获取库存 集合
  getStockMaterialsViewPage = (val: Pagination<StockPutawayEntity>) => {
    return request.postForPage(`${stockPathName}/page`, val);
  };
  // 用于 出库 查询库存物料集合
  getStockDnPage = (val: Pagination<StockDnSearchEntity>) => {
    return request.postForPage(`${pathName}/stockDnPage`, val);
  };
  // 用于 调拨 查询库存物料集合
  getStockTfPage = (val: Pagination<StockDnSearchEntity>) => {
    return request.postForPage(`${pathName}/stockTfPage`, val);
  };
  // 用于 出库 销售订单 获取库存物料集合
  getDeliveryStocks = (val: DeliveryStockEntity) => {
    return request.post(`${pathName}/deliveryStocks`, val);
  };
  // 用于 入库 销售订单 获取库存物料集合
  getDeliveryAsnStocks = (val: DeliveryStockEntity) => {
    return request.post(`${pathName}/deliveryAsnStocks`, val);
  };
}
const stockApi = new StockApi();

class StockDetailApi {
  getPage = (val: Pagination<StockDetailSearchEntity>) => {
    return request.postForPage(`${stockPathName}/page`, val);
  };
  getPackPage = (val: Pagination<StockDetailSearchEntity>) => {
    return request.postForPage(`${stockPathName}/packPage`, val);
  };
  // 获取库存 集合
  // 必传 asnId
  // 新增 keyword 模糊搜索 （物料名称、规格型号）
  getPageByKeyword = (val: Pagination<StockPutawayEntity>) => {
    return request.postForPage(`${stockPathName}/pageByKeyword`, val);
  };
  // 获取物料凭证历史记录
  // stockMaterialId
  SapMaterialProof = (val: any) => {
    return request.get(`SapMaterialProof/getProof/${val}`);
  };
  // 根据条件查询并 导出 库存明细
  export = (val: StockDetailSearchEntity) => {
    return request.post(`${stockPathName}/export`, val, {
      responseType: 'blob'
    });
  };
}

const stockDetailApi = new StockDetailApi();

class StockMaterialApi {
  // 拆包
  unpackStock = (val?: any) => {
    return request.post(`${stockMaterialPathName}/unpackStock`, val);
  };
  // 合包
  packStock = (val?: any) => {
    return request.post(`${stockMaterialPathName}/packStock`, val);
  };
}
const stockMaterialApi = new StockMaterialApi();

export { stockApi, stockDetailApi, stockMaterialApi };
