/**
 * Orchestrates the execution of pipeline steps.
 */
export class Pipeline {
    steps = [];
    /**
     * Adds a step to the pipeline.
     */
    addStep(step) {
        this.steps.push(step);
        return this;
    }
    /**
     * Executes all steps in the sequence for which shouldRun returns true.
     */
    async execute(context) {
        for (const step of this.steps) {
            if (await step.shouldRun(context)) {
                console.log(`[Pipeline] Running step: ${step.name}`);
                try {
                    await step.run(context);
                }
                catch (error) {
                    console.error(`[Pipeline] Step ${step.name} failed:`, error);
                    context.errors.push(error instanceof Error ? error : new Error(String(error)));
                    // We might want to stop the pipeline depending on the failure
                    break;
                }
            }
            else {
                console.log(`[Pipeline] Skipping step: ${step.name}`);
            }
        }
    }
}
