import ReportTemplateAPI from '../../api/restApis/ReportTemplateAPI'
import HelperUtil from '@/utils/HelperUtil'
import {REPORT_TEMPLATE_KEY} from '../../utils/constantCollection'
import DeviceAPI from "../../api/restApis/DeviceAPI";

// 静态方法
let staticMethods = {
  /**
   * @Description  : 创建
   * @author       : ls
   * @date         : 2020/5/2 14:17
   * @param        :
   * @return       :
   */
  createReportTemplate: function (template) {
    return ReportTemplateAPI.addReportTemplate(template).then(result => {
      if (result.data.result) {
      } else {
        return HelperUtil.returnPromiseRejectObj(result)
      }
    })
  },
  /**
   * @Description  : 修改
   * @author       : ls
   * @date         : 2020/5/2 14:19
   * @param        :
   * @return       :
   */
  updateReportTemplate: function (template) {
    return ReportTemplateAPI.putModifyReportTemplate(template).then(result => {
      if (result.data.result) {
      } else {
        return HelperUtil.returnPromiseRejectObj(result)
      }
    })
  },
  /**
   * @Description  : 删除
   * @author       : ls
   * @date         : 2020/5/2 14:19
   * @param        :
   * @return       :
   */
  delateReportTemplate: function (keyList) {
    return ReportTemplateAPI.deleteDeleteReportTemplate(keyList).then(result => {
      if (result.data.result) {
      } else {
        return HelperUtil.returnPromiseRejectObj(result)
      }
    })
  },
  /**
   * @Description  : 获取所有
   * @author       : ls
   * @date         : 2020/5/2 14:20
   * @param        :
   * @return       :
   */
  getAllReportTemplateCollection: function () {
    return ReportTemplateAPI.getReportTemplateCollection().then(result => {
      if (result.data.result) {
        return HelperUtil.arrayToObject(result.data.returnValue, REPORT_TEMPLATE_KEY)
      } else {
        return HelperUtil.returnPromiseRejectObj(result)
      }
    })
  },

  /**
   * @Description  : 分页查询所有
   * @author       : ls
   * @date         : 2020/5/6 16:13
   * @param        :
   * @return       :
   */
  queryReportTemplateDataSplitNumber: function (beginItem, endItem, selectList) {
    return ReportTemplateAPI.putReportTemListQueryterms(beginItem, endItem, selectList).then(result => {
      if (result.data.result) {
        return HelperUtil.arrayToObject(result.data.returnValue, REPORT_TEMPLATE_KEY)
      } else {
        return HelperUtil.returnPromiseRejectObj(result)
      }
    })
  },
  /**
   * @Description  : 查询总数service
   * @author       : ls
   * @date         : 2020/5/6 16:12
   * @param        :
   * @return       :
   */
  queryReportTemplateTotalNumber: function (selectList) {
    return ReportTemplateAPI.putReportTemplateListCounts(selectList).then(result => {
      if (result.data.result) {
        return result.data.returnValue
      } else {
        return HelperUtil.returnPromiseRejectObj(result)
      }
    })
  },
  /**
   * @Description  : 条件查询service
   * @author       : ls
   * @date         : 2020/4/22 17:39
   * @param        :
   * @return       :
   */
  queryReportTemplate: function (conditionSet) {
    return ReportTemplateAPI.putReportTemplateCollection(conditionSet).then(result => {
      if (result.data.result) {
        return HelperUtil.arrayToObject(result.data.returnValue, REPORT_TEMPLATE_KEY)
      } else {
        return HelperUtil.returnPromiseRejectObj(result)
      }
    })
  }
}

function ReportTemplateService () {
  return Object.freeze(Object.assign(
    {
      // object methods comes here
    },
    staticMethods
  ))
}
// inject static methods
Object.assign(ReportTemplateService, staticMethods)
export default ReportTemplateService
