import helper from 'src/Utils/helper';
import { request } from '../../boot/axios';
import { Pagination } from '../class';
import { EquipmentSearchEntity, EquipmentEntity } from './model/equipment';
const pathName = 'Equipment/';

class EquipmentApi {
  // 获取设备分页
  getEquipmentPageList = (val: Pagination<EquipmentSearchEntity>) => {
    let format = `?page=${val.page}&size=${val.rowsPerPage}`;
    if (val.data.equipmentName) {
      format += `&equipmentName=${val.data.equipmentName}`;
    }
    if (val.data.equipmentCode) {
      format += `&equipmentCode=${val.data.equipmentCode}`;
    }
    if (val.data.equipmentType) {
      format += `&equipmentType=${val.data.equipmentType}`;
    }
    if (val.data.activated != undefined && val.data.activated != null) {
      format += `&activated=${val.data.activated}`;
    }
    return request.get(`${pathName}GetEquipmentPageList${format}`);
  };

  // 获取设备列表
  getEquipmentList = (val: EquipmentSearchEntity) => {
    const format = helper.params(val);
    return request.get(`${pathName}GetEquipmentList${format}`);
  };

  // 根据 id 获取设备明细
  getEquipmentDetail = (id: any) => {
    return request.get(`${pathName}GetEquipmentDetail?id=${id}`);
  };

  // 添加
  add = (val: EquipmentEntity) => {
    return request.post(`${pathName}AddEquipment`, val);
  };

  // 修改
  edit = (val: EquipmentEntity) => {
    return request.post(`${pathName}UpdateEquipment`, val);
  };

  // 删除
  delete = (id: any) => {
    return request.post(`${pathName}DeleteEquipment?id=${id}`);
  };
}
const equipmentApi = new EquipmentApi();

export { equipmentApi };
