"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.OAuth = exports.KRAuth = exports.EAuth = exports.BaseAuth = void 0;

var _bsGlobal = require("../../utils/bs-global");

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }

function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }

function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }

function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }

function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }

var BaseAuth = /*#__PURE__*/function () {
  function BaseAuth() {
    _classCallCheck(this, BaseAuth);

    this.loginUserInfor = (0, _bsGlobal.getBSGlobal)("loginUserInfo");
  } // 老板


  _createClass(BaseAuth, [{
    key: "isBoss",
    value: function isBoss() {
      // console.log('isboss', this.loginUserInfor.IsBoss)
      return this.loginUserInfor.IsBoss;
    } // 超管、助理、目标管理员

  }, {
    key: "isManager",
    value: function isManager() {
      // console.log('ismanager', this.loginUserInfor.IsOkrManager)
      return this.loginUserInfor.IsOkrManager;
    }
  }]);

  return BaseAuth;
}();

exports.BaseAuth = BaseAuth;

var OAuth = /*#__PURE__*/function (_BaseAuth) {
  _inherits(OAuth, _BaseAuth);

  var _super = _createSuper(OAuth);

  function OAuth(props) {
    var _this;

    _classCallCheck(this, OAuth);

    _this = _super.call(this, props);
    var principalUser = props.principalUser,
        createUserId = props.createUserId;
    _this.userId = _this.loginUserInfor.Id;
    _this.principalUser = principalUser;
    _this.createUserId = createUserId;
    return _this;
  } // 創建人、發起人


  _createClass(OAuth, [{
    key: "isCreater",
    value: function isCreater() {
      // console.log('o iscreater', this.userId, this.createUserId)
      return this.userId == this.createUserId;
    } // 負責人

  }, {
    key: "isPrincipalUser",
    value: function isPrincipalUser() {
      // console.log('o isp', this.userId, this.principalUser.userId)
      return this.userId == this.principalUser.userId;
    } // 有操作OKR的權限

  }, {
    key: "hasAuth",
    value: function hasAuth() {
      return this.isBoss() || this.isManager() || this.isCreater() || this.isPrincipalUser();
    }
  }]);

  return OAuth;
}(BaseAuth);

exports.OAuth = OAuth;

var KRAuth = /*#__PURE__*/function (_BaseAuth2) {
  _inherits(KRAuth, _BaseAuth2);

  var _super2 = _createSuper(KRAuth);

  function KRAuth(props) {
    var _this2;

    _classCallCheck(this, KRAuth);

    _this2 = _super2.call(this, props);
    var user = props.user,
        createUserId = props.createUserId;
    _this2.loginUserInfor = (0, _bsGlobal.getBSGlobal)("loginUserInfo");
    _this2.userId = _this2.loginUserInfor.Id;
    _this2.user = user;
    _this2.createUserId = createUserId;
    return _this2;
  } // 創建人、發起人


  _createClass(KRAuth, [{
    key: "isCreater",
    value: function isCreater() {
      // console.log('kr iscreater', this.userId, this.createUserId)
      return this.userId == this.createUserId;
    } // 負責人

  }, {
    key: "isPrincipalUser",
    value: function isPrincipalUser() {
      // console.log('kr isp', this.userId, this.user.userId)
      return this.userId == this.user.userId;
    } // 有操作KR的權限

  }, {
    key: "hasAuth",
    value: function hasAuth() {
      return this.isBoss() || this.isManager() || this.isCreater() || this.isPrincipalUser();
    }
  }]);

  return KRAuth;
}(BaseAuth);

exports.KRAuth = KRAuth;

var EAuth = /*#__PURE__*/function (_BaseAuth3) {
  _inherits(EAuth, _BaseAuth3);

  var _super3 = _createSuper(EAuth);

  function EAuth(props) {
    var _this3;

    _classCallCheck(this, EAuth);

    _this3 = _super3.call(this, props);
    var principalUser = props.principalUser,
        user = props.user;
    _this3.userId = _this3.loginUserInfor.Id;
    _this3.principalUser = principalUser;
    _this3.user = user;
    return _this3;
  } // 創建人、發起人


  _createClass(EAuth, [{
    key: "isCreater",
    value: function isCreater() {
      // console.log('e iscreater', this.userId, this.user.userId)
      return this.userId == this.user.userId;
    } // 負責人

  }, {
    key: "isPrincipalUser",
    value: function isPrincipalUser() {
      // console.log('e isp', this.userId, this.principalUser.userId)
      return this.userId == this.principalUser.userId;
    } // 有操作KR的權限

  }, {
    key: "hasAuth",
    value: function hasAuth() {
      return this.isBoss() || this.isManager() || this.isCreater() || this.isPrincipalUser();
    }
  }]);

  return EAuth;
}(BaseAuth);

exports.EAuth = EAuth;