import { Thing } from '../components/thing';
import { FlowService } from './flow.service';
var ExecutionService = (function () {
    function ExecutionService(flow, things, scope) {
        this.flow = flow;
        this.scope = scope;
        this.things = things;
        this.createMap(things);
        this.flowService = new FlowService(flow, scope);
    }
    ExecutionService.prototype.createMap = function (things) {
        var _this = this;
        this.thingsMap = { "start": new Thing() };
        things.forEach(function (thing) {
            if (_this.thingsMap[thing.key]) {
                throw Error('Error inializing otpp execution. Multiple things with the same key');
            }
            _this.thingsMap[thing.key] = thing;
        });
    };
    ExecutionService.prototype.start = function () {
        var state = this.flowService.start();
        return this.getThing(state);
    };
    ExecutionService.prototype.next = function () {
        var state = this.flowService.next();
        return this.getThing(state);
    };
    ExecutionService.prototype.go = function (state) {
        this.flowService.go(state);
        return this.getThing(state);
    };
    ExecutionService.prototype.getCurrent = function () {
        return this.getThing(this.flowService.current);
    };
    ExecutionService.prototype.getThing = function (state) {
        var thing = this.thingsMap[state];
        if (!thing)
            throw Error('OTPP: no "Thing" found for state "' + state + '"');
        return thing;
    };
    return ExecutionService;
}());
export { ExecutionService };
//# sourceMappingURL=execution.service.js.map