/**
 * Filter Step — evaluate conditions, skip pipeline if not met.
 * Config: { conditions: [{ field, operator, value }] }
 */

import { registerStepExecutor, pipelineEngine } from '../pipeline-engine';
import { PipelineStep, PipelineContext, StepExecutorResult } from '../../types/pipeline';

async function executeFilter(
  step: PipelineStep,
  context: PipelineContext,
  _executionId: number
): Promise<StepExecutorResult> {
  const conditions = step.config.conditions || [];

  if (conditions.length === 0) {
    return { success: true, output: { filter_result: 'passed' } };
  }

  const passed = pipelineEngine.evaluateConditions(conditions, context);

  if (!passed) {
    return { success: false, error: 'Filter conditions not met — pipeline skipped' };
  }

  return { success: true, output: { filter_result: 'passed' } };
}

registerStepExecutor('filter', executeFilter);
