text: "use strict";
  var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
      var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
      if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
      else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
      return c > 3 && r && Object.defineProperty(target, key, r), r;
  };
  var __metadata = (this && this.__metadata) || function (k, v) {
      if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
  };
  Object.defineProperty(exports, "__esModule", { value: true });
  exports.RoleGuard = void 0;
  const common_1 = require("@nestjs/common");
  const core_1 = require("@nestjs/core");
  const auth_service_1 = require("../auth.service");
  const meta_1 = require("../decorators/meta");
  const constants_1 = require("../constants");
  const utils_1 = require("../utils/utils");
  let RoleGuard = class RoleGuard {
      constructor(reflector, authServicec) {
          this.reflector = reflector;
          this.authServicec = authServicec;
      }
      async canActivate(context) {
          const rolesMetaData = this.reflector.getAllAndOverride(meta_1.META_ROLES, [context.getClass(), context.getHandler()]);
          if (!rolesMetaData || rolesMetaData.roles.length === 0) {
              return true;
          }
          if (rolesMetaData && !rolesMetaData.mode) {
              rolesMetaData.mode = constants_1.RoleMatchingMode.ANY;
          }
          let [request] = (0, utils_1.extractRequest)(context);
          if (!request["accessTokenJWT"] || !request["user"]) {
              return false;
          }
          const grant = await this.authServicec.authenticate(request["accessTokenJWT"]);
          const accessToken = grant.access_token;
          console.log(request["user"].resource_access.account.roles);
          const grented = rolesMetaData.mode === constants_1.RoleMatchingMode.ANY
              ? rolesMetaData.roles.some(role => accessToken.hasRole(role))
              : rolesMetaData.roles.every(role => accessToken.hasRole(role));
          console.log(grented);
          return grented;
      }
  };
  RoleGuard = __decorate([
      (0, common_1.Injectable)(),
      __metadata("design:paramtypes", [core_1.Reflector,
          auth_service_1.AuthService])
  ], RoleGuard);
  exports.RoleGuard = RoleGuard;
  //# sourceMappingURL=role.guard.js.map