package com.cameleer.server.core.storage;

import java.time.Instant;
import java.util.List;
import java.util.Optional;

public interface ExecutionStore {

    Optional<ExecutionRecord> findById(String executionId);

    List<ProcessorRecord> findProcessors(String executionId);

    Optional<ProcessorRecord> findProcessorById(String executionId, String processorId);

    record ExecutionRecord(
            String executionId, String routeId, String instanceId, String applicationId,
            String environment,
            String status, String correlationId, String exchangeId,
            Instant startTime, Instant endTime, Long durationMs,
            String errorMessage, String errorStacktrace, String diagramContentHash,
            String engineLevel,
            String inputBody, String outputBody, String inputHeaders, String outputHeaders,
            String inputProperties, String outputProperties,
            String attributes,
            String errorType, String errorCategory,
            String rootCauseType, String rootCauseMessage,
            String traceId, String spanId,
            String processorsJson,
            boolean hasTraceData,
            boolean isReplay
    ) {}

    record ProcessorRecord(
            String executionId, String processorId, String processorType,
            String applicationId, String routeId,
            int depth, String parentProcessorId, String status,
            Instant startTime, Instant endTime, Long durationMs,
            String errorMessage, String errorStacktrace,
            String inputBody, String outputBody, String inputHeaders, String outputHeaders,
            String inputProperties, String outputProperties,
            String attributes,
            Integer loopIndex, Integer loopSize,
            Integer splitIndex, Integer splitSize,
            Integer multicastIndex,
            String resolvedEndpointUri,
            String errorType, String errorCategory,
            String rootCauseType, String rootCauseMessage,
            String errorHandlerType, String circuitBreakerState,
            Boolean fallbackTriggered,
            // New fields for ClickHouse seq-based model
            Integer seq,
            Integer parentSeq,
            Integer iteration,
            Integer iterationSize,
            Boolean filterMatched,
            Boolean duplicateMessage
    ) {}

    default Optional<ProcessorRecord> findProcessorBySeq(String executionId, int seq) {
        return Optional.empty();
    }
}
