"use strict";
var AccessRightsUserService_1;
Object.defineProperty(exports, "__esModule", { value: true });
exports.AccessRightsUserService = void 0;
const tslib_1 = require("tslib");
const authorization_1 = require("@loopback/authorization");
const core_1 = require("@loopback/core");
const entity_name_1 = require("../../models/entity-name");
const acl_ctx_model_1 = require("./../../models/acl-ctx.model");
const access_rights_abstract_service_1 = require("./access-rights-abstract.service");
const access_rights_const_1 = require("./access-rights.const");
const access_rights_service_1 = require("./access-rights.service");
let AccessRightsUserService = AccessRightsUserService_1 = class AccessRightsUserService extends access_rights_abstract_service_1.AccessRightsAbstractService {
    constructor(accessRightsService) {
        super(access_rights_const_1.ACCESS_RIGHT_PROVIDER, AccessRightsUserService_1.name, accessRightsService, entity_name_1.EntityName.user);
        this.accessRightsService = accessRightsService;
    }
    async cleanReturnedEntity(entity, ctx) {
        const user = entity;
        if (!user.entityCtx) {
            user.entityCtx = { entityType: entity_name_1.EntityName.user };
        }
        if (!user.entityCtx.aclCtx) {
            user.entityCtx.aclCtx = new acl_ctx_model_1.AclCtx();
        }
        user.entityCtx.aclCtx.rights.read = true;
        // TODO: clean the object here;
    }
    async authorizeRead(ctx, context) {
        // TODO: check if reading Me
        return authorization_1.AuthorizationDecision.ALLOW;
    }
    async authorizeCreate(ctx, context) {
        // TODO: check if not login and is user creation
        return authorization_1.AuthorizationDecision.ALLOW;
    }
    async authorizeUpdate(ctx, context) {
        // TODO: check if updating Me
        return authorization_1.AuthorizationDecision.DENY;
    }
    async authorizeDelete(ctx, context) {
        // TODO: check if deleting Me
        return authorization_1.AuthorizationDecision.DENY;
    }
};
AccessRightsUserService = AccessRightsUserService_1 = tslib_1.__decorate([
    core_1.injectable({ scope: core_1.BindingScope.SINGLETON }),
    tslib_1.__param(0, core_1.service(access_rights_service_1.AccessRightsService)),
    tslib_1.__metadata("design:paramtypes", [access_rights_service_1.AccessRightsService])
], AccessRightsUserService);
exports.AccessRightsUserService = AccessRightsUserService;
//# sourceMappingURL=access-rights-user.service.js.map