import IndexTemplateAPI from '../../api/restApis/IndexTemplateAPI'
import HelperUtil from '../../utils/HelperUtil'
import {SUBNET_KEY, INDEX_TEMPLATE_KEY, PERFORM_TASK_KEY} from '../../utils/constantCollection'
import CollectTaskAPI from "../../api/restApis/CollectTaskAPI";

// 静态方法
let staticMethods = {
  /**
   * @Description  : 获取所有
   * @author       : ls
   * @date         : 2020/4/27 17:04
   * @param        :
   * @return       :
   */
  getAllIndexTemplateCollection: function () {
    return IndexTemplateAPI.getIndexTemplateCollection().then(result => {
      if (result.data.result) {
        return HelperUtil.arrayToObject(result.data.returnValue, INDEX_TEMPLATE_KEY)
      } else {
        return HelperUtil.returnPromiseRejectObj(result)
      }
    })
  },

  /**
   * @Description  : 创建指标模板
   * @author       : ls
   * @date         : 2020/4/27 9:33
   * @param        :
   * @return       :
   */
  createIndexTemplate: function (indexT) {
    return IndexTemplateAPI.postAddIndexTemplate(indexT).then(result => {
      if (result.data.result) {
      } else {
        return HelperUtil.returnPromiseRejectObj(result)
      }
    })
  },

  /**
   * @Description  : shanchuzhibiao
   * @author       : ls
   * @date         : 2020/4/27 9:46
   * @param        :
   * @return       :
   */
  deleteIndexTemplate: function (delList) {
    return IndexTemplateAPI.deleteDeleteIndexTemplate(delList).then(result => {
      if (result.data.result) {
      } else {
        return HelperUtil.returnPromiseRejectObj(result)
      }
    })
  },
  /**
   * @Description  : 修改指标模板
   * @author       : ls
   * @date         : 2020/4/27 17:07
   * @param        :
   * @return       :
   */
  modifyIndexTemplate: function (indeT) {
    return IndexTemplateAPI.putModifyIndexTemplate(indeT).then(result => {
      if (result.data.result) {
      } else {
        return HelperUtil.returnPromiseRejectObj(result)
      }
    })
  },

  /**
   * @Description  : 条件查询
   * @author       : ls
   * @date         : 2020/4/27 10:08
   * @param        :
   * @return       :
   */
  queryIndexTemplate: function (conditionSet) {
    return IndexTemplateAPI.putConditionQueryIndexTemplate(conditionSet).then(result => {
      if (result.data.result) {
        return HelperUtil.arrayToObject(result.data.returnValue, INDEX_TEMPLATE_KEY)
      } else {
        return HelperUtil.returnPromiseRejectObj(result)
      }
    })
  },
  /**
   * @Description  : 总数
   * @author       : ls
   * @date         : 2020/6/10 15:52
   * @param        :
   * @return       :
   */
  getIndexTemplateTotalCounts: function (conditionSet) {
    return IndexTemplateAPI.getIndexTemplateCounts(conditionSet).then(result => {
      if (result.data.result) {
        return result.data.returnValue
      } else {
        return HelperUtil.returnPromiseRejectObj(result)
      }
    })
  },
  /**
   * @Description  : 分页查询
   * @author       : ls
   * @date         : 2020/6/10 16:01
   * @param        :
   * @return       :
   */
  queryIndexTemplateListPaging: function (beginItem, endItem, selectList) {
    return IndexTemplateAPI.queryIndexTemplatePaging(beginItem, endItem, selectList).then(result => {
      if (result.data.result) {
        return HelperUtil.arrayToObject(result.data.returnValue, PERFORM_TASK_KEY)
      } else {
        return HelperUtil.returnPromiseRejectObj(result)
      }
    })
  }
}

function IndexTeplateService () {
  return Object.freeze(Object.assign(
    {
    },
    staticMethods
  ))
}
// inject static methods
Object.assign(IndexTeplateService, staticMethods)
export default IndexTeplateService
