package at.procon.eventhub.processing.eventprocessing.plan;

import java.util.List;
import org.springframework.stereotype.Service;

@Service
public class RuntimeProcessingExecutionService {

    private final RuntimeProcessingPlanRegistry planRegistry;

    public RuntimeProcessingExecutionService(RuntimeProcessingPlanRegistry planRegistry) {
        this.planRegistry = planRegistry;
    }

    public RuntimeProcessingExecutionResultDto execute(RuntimeProcessingExecutionApiRequest request) {
        RuntimeProcessingPlan plan = planRegistry.require(request.processingPlanKey());
        plan.validatePartitioning(request.partitioning());
        return plan.execute(request);
    }

    public List<RuntimeProcessingPlanDescriptorDto> listPlans() {
        return planRegistry.planDescriptors();
    }
}
