import UserGroupAPI from "../../api/restApis/UserGroupAPI"
import HelperUtil from '../../utils/HelperUtil'
import {AUTHORITY_KEY, USERGROUP_KEY} from "../../utils/constantCollection"
import LocationAPI from "../../api/restApis/LocationAPI";
import LocationService from "./LocationService";

let staticMethods = {
  //获取全部权限集合
  getAllAuthorities: function () {
    return UserGroupAPI.getAllAuthorityCollection().then(result => {
      if (result.data.result) {
        return HelperUtil.arrayToObject(result.data.returnValue, AUTHORITY_KEY)
      } else {
        return HelperUtil.returnPromiseRejectObj(result)
      }
    })
  },

  //获取所有用户组
  getAllUserGroups: function () {
    return UserGroupAPI.getUserGroupConfig().then(result => {
      if (result.data.result) {
        return HelperUtil.arrayToObject(result.data.returnValue, USERGROUP_KEY)
      } else {
        return HelperUtil.returnPromiseRejectObj(result)
      }
    })
  },

  //创建用户组
  createUserGroup: function (userGroup) {
    return UserGroupAPI.postAddUserGroup(userGroup).then(result => {
      if (result.data.result) {
      } else {
        return HelperUtil.returnPromiseRejectObj(result);
      }
    });
  },

  //删除用户组
  deleteUserGroup: function (userGroupKeyList) {
    return UserGroupAPI.deleteDeleteUserGroup(userGroupKeyList).then(result => {
      if (result.data.result) {
      } else {
        return HelperUtil.returnPromiseRejectObj(result)
      }
    })
  },

  updateUserGroup: function (userGroup) {
    return UserGroupAPI.putModifyUserGroup(userGroup).then(result => {
      if (result.data.result) {
      } else {
        return HelperUtil.returnPromiseRejectObj(result)
      }
    })
  }
}

function UserGroupService (websocketService = null) {
  return Object.freeze(Object.assign(
    {
      // object methods comes here
    },
    staticMethods
  ))
}

Object.assign(UserGroupService, staticMethods)
export default UserGroupService
