"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FakeFeatureLifecycleStore = void 0;
class FakeFeatureLifecycleStore {
    constructor() {
        this.lifecycles = {};
    }
    async insert(featureLifecycleStages) {
        await Promise.all(featureLifecycleStages.map((stage) => this.insertOne(stage)));
    }
    async insertOne(featureLifecycleStage) {
        if (await this.stageExists(featureLifecycleStage)) {
            return;
        }
        const existingStages = await this.get(featureLifecycleStage.feature);
        this.lifecycles[featureLifecycleStage.feature] = [
            ...existingStages,
            {
                stage: featureLifecycleStage.stage,
                enteredStageAt: new Date(),
            },
        ];
    }
    async get(feature) {
        return this.lifecycles[feature] || [];
    }
    async delete(feature) {
        this.lifecycles[feature] = [];
    }
    async stageExists(stage) {
        const lifecycle = await this.get(stage.feature);
        return Boolean(lifecycle.find((s) => s.stage === stage.stage));
    }
    async deleteStage(stage) {
        if (!this.lifecycles[stage.feature]) {
            return;
        }
        const updatedStages = this.lifecycles[stage.feature].filter((s) => s.stage !== stage.stage);
        this.lifecycles[stage.feature] = updatedStages;
    }
}
exports.FakeFeatureLifecycleStore = FakeFeatureLifecycleStore;
//# sourceMappingURL=fake-feature-lifecycle-store.js.map