
// 静态方法
import HelperUtil from "../../utils/HelperUtil";
import {
  CABINET_KEY,
  SNAPSHOT_KEY,
  CABINET_DOWNLOAD_FILE_NAME,
} from "../../utils/constantCollection";
import CabinetAPI from "../../api/restApis/CabinetAPI";
import SnapshotAPI from "../../api/restApis/SnapshotAPI";
import FirmWareAPI from "../../api/restApis/FirmWareAPI";

let staticMethods = {

  // 获取所有快照
  getAllSnapshotCollection: function () {
    return SnapshotAPI.getSnapshotCollection().then(result => {
      if (result.data.result) {
        return HelperUtil.arrayToObject(result.data.returnValue, SNAPSHOT_KEY)
      } else {
        return HelperUtil.returnPromiseRejectObj(result)
      }
    })
  },

  // 删除快照
  deleteSnapshot: function (snapshotKeyList) {
    return SnapshotAPI.deleteDeleteSnapshot(snapshotKeyList).then(result => {
      if (result.data.result) {
      } else {
        return HelperUtil.returnPromiseRejectObj(result)
      }
    })
  },

  // 条件查询快照
  conditionQuerySnapshot: function (conditionSet) {
    return SnapshotAPI.putConditionQuerySnapshot(conditionSet).then(result => {
      if (result.data.result) {
        return HelperUtil.arrayToObject(result.data.returnValue, SNAPSHOT_KEY);
      } else {
        return HelperUtil.returnPromiseRejectObj(result)
      }
    })
  },

  // 添加快照
  addSnapshot: function (snapshot, options) {
    return SnapshotAPI.postAddSnapshot(snapshot, options).then(result => {
      if (result.data.result) {
      }else{
        return HelperUtil.returnPromiseRejectObj(result);
      }
    });
  },

  // 回退快照
  recoverSnapshot: function (snapshotKey) {
    return SnapshotAPI.getRecoverSnapshot(snapshotKey).then(result => {
      if (result.data.result) {
        return result.data.result
      } else {
        return HelperUtil.returnPromiseRejectObj(result)
      }
    })
  }
}

function CabinetService (websocketService = null) {

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