import helper from 'src/Utils/helper';
import { request } from '../../boot/axios';
import { Pagination } from '../class';
import {
  EquipmentRecord,
  EquipmentNoTimeRecord,
  EquipmentOEE
} from './model/equipmentRecord';
const pathName = 'EquipmentRecord/';

class EquipmentRecordApi {
  // 获取设备状态记录分页 设备+时间跨度
  getEquipmentRecordPageList = (val: Pagination<EquipmentRecord>) => {
    let format = `?page=${val.page}&size=${val.rowsPerPage}`;
    if (val.data.equipmentId) {
      format += `&equipmentId=${val.data.equipmentId}`;
    }
    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.begTime) {
      format += `&begTime=${val.data.begTime}`;
    }
    if (val.data.endTime) {
      format += `&endTime=${val.data.endTime}`;
    }
    return request.get(`${pathName}GetEquipmentRecordPageList${format}`);
  };

  // 获取设备状态记录列表 设备+时间跨度
  getEquipmentRecordList = (val: EquipmentRecord) => {
    const format = helper.params(val);
    return request.get(`${pathName}GetEquipmentRecordList${format}`);
  };

  // 获取设备状态记录统计（日）分页
  getEquipmentRecordDayTotalPageList = (val: Pagination<EquipmentRecord>) => {
    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.begTime) {
      format += `&begTime=${val.data.begTime}`;
    }
    if (val.data.endTime) {
      format += `&endTime=${val.data.endTime}`;
    }
    return request.get(
      `${pathName}GetEquipmentRecordDayTotalPageList${format}`
    );
  };

  // 获取设备状态记录统计（日）列表
  getEquipmentRecordDayTotalList = (val: EquipmentRecord) => {
    const format = helper.params(val);
    return request.get(`${pathName}GetEquipmentRecordDayTotalList${format}`);
  };

  // 获取设备状态记录统计分页 时间跨度
  getEquipmentRecordTotalPageList = (
    val: Pagination<EquipmentNoTimeRecord>
  ) => {
    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.begTime) {
      format += `&begTime=${val.data.begTime}`;
    }
    if (val.data.endTime) {
      format += `&endTime=${val.data.endTime}`;
    }
    return request.get(`${pathName}GetEquipmentRecordTotalPageList${format}`);
  };

  // 获取设备状态记录统计列表 时间跨度
  getEquipmentRecordTotalList = (val: EquipmentNoTimeRecord) => {
    const format = helper.params(val);
    return request.get(`${pathName}GetEquipmentRecordTotalList${format}`);
  };

  // 根据 id 获取设备记录统计
  getEquipmentRecordTotalDetail = (id: any) => {
    return request.get(
      `${pathName}GetEquipmentRecordTotalDetail?equipmentId=${id}`
    );
  };


  // 获取 设备记录 OEE月度统计
  getEquipmentRecordOEEMonthTotal = () => {
    return request.get(`${pathName}GetEquipmentRecordOEEMonthTotal`);
  };

  // 根据 获取设备OEE 信息
  GetEquipmentOEEMonthTotal = (val: EquipmentOEE) => {
  const format = helper.params(val);
    return request.get(
      `${pathName}GetEquipmentOEEMonthTotal${format}`
    );
  };

  // 获取设备总览
  getEquipmentStateView = () => {
    return request.get(`${pathName}GetEquipmentStateView`);
  };

  // 获取报警设备列表
  getEquipmentAlarmList = () => {
    return request.get(`${pathName}GetEquipmentAlarmList`);
  };

  // 获取设备状态记录月统计
  getEquipmentRecordStateMonthTotal = () => {
    return request.get(`${pathName}GetEquipmentRecordStateMonthTotal`);
  };

  // 获取设备记录开炉次数月统计
  getEquipmentRecordFurnaceMonthTotal = () => {
    return request.get(`${pathName}GetEquipmentRecordFurnaceMonthTotal`);
  };
}
const equipmentRecordApi = new EquipmentRecordApi();

export { equipmentRecordApi };
