"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const event_1 = require("./event");
class EndEventEntity extends event_1.EventEntity {
    constructor(nodeInstanceEntityDependencyHelper, entityDependencyHelper, context, schema, propertyBag, entityType) {
        super(nodeInstanceEntityDependencyHelper, entityDependencyHelper, context, schema, propertyBag, entityType);
    }
    async initialize() {
        await super.initialize(this);
    }
    async execute(context) {
        this.state = 'progress';
        const processToken = this.processToken;
        const currentToken = processToken.data.current;
        const data = {
            action: 'endEvent',
            data: currentToken,
            endEventKey: this.key,
        };
        const msg = this.messageBusService.createEntityMessage(data, this, context);
        if (this.participant) {
            await this.messageBusService.publish(`/participant/${this.participant}`, msg);
        }
        else {
            const configuredRole = await this.nodeDef.lane.role;
            const roles = configuredRole ? [configuredRole] : ['guest', 'default'];
            const flattenedRoles = this.iamService.flattenRoles(roles);
            for (const flatRole of flattenedRoles) {
                await this.messageBusService.publish(`/role/${flatRole}`, msg);
            }
        }
        await this.messageBusService.publish(`/processengine/process/${this.process.id}`, msg);
        this.changeState(context, 'end', this);
    }
}
exports.EndEventEntity = EndEventEntity;

//# sourceMappingURL=end_event.js.map
