"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AccessRightsAbstractService = void 0;
const authorization_1 = require("@loopback/authorization");
const access_rights_const_1 = require("./access-rights.const");
class AccessRightsAbstractService {
    constructor(providerId, serviceId, accessRightsService, resource) {
        this.providerId = providerId;
        this.serviceId = serviceId;
        this.accessRightsService = accessRightsService;
        this.resource = resource;
        this.accessRightsService.registerAccessRightsService(resource, this);
    }
    async authorize(ctx, context) {
        var _a;
        if (0 < ((_a = context.scopes) === null || _a === void 0 ? void 0 : _a.length)) {
            switch (context.scopes[0]) {
                case access_rights_const_1.AccessRightsScope.create:
                    return this.authorizeCreate(ctx, context);
                case access_rights_const_1.AccessRightsScope.read:
                    return this.authorizeRead(ctx, context);
                case access_rights_const_1.AccessRightsScope.update:
                    return this.authorizeUpdate(ctx, context);
                case access_rights_const_1.AccessRightsScope.delete:
                    return this.authorizeDelete(ctx, context);
            }
        }
        return authorization_1.AuthorizationDecision.DENY;
    }
}
exports.AccessRightsAbstractService = AccessRightsAbstractService;
//# sourceMappingURL=access-rights-abstract.service.js.map