package com.cameleer.server.core.ingestion;

import com.cameleer.server.core.storage.DiagramStore;
import com.cameleer.server.core.storage.model.MetricsSnapshot;

import java.util.List;

/**
 * Diagram + metrics ingestion facade.
 *
 * <p>Execution ingestion went through this class via the {@code RouteExecution}
 * shape until the ClickHouse chunked pipeline took over — {@code ChunkAccumulator}
 * now writes executions directly from the {@code /api/v1/data/executions}
 * controller, so this class no longer needs an ExecutionStore or event-publisher
 * dependency.
 */
public class IngestionService {

    private final DiagramStore diagramStore;
    private final WriteBuffer<MetricsSnapshot> metricsBuffer;

    public IngestionService(DiagramStore diagramStore,
                            WriteBuffer<MetricsSnapshot> metricsBuffer) {
        this.diagramStore = diagramStore;
        this.metricsBuffer = metricsBuffer;
    }

    public void ingestDiagram(TaggedDiagram diagram) {
        diagramStore.store(diagram);
    }

    public boolean acceptMetrics(List<MetricsSnapshot> metrics) {
        return metricsBuffer.offerBatch(metrics);
    }

    public int getMetricsBufferDepth() {
        return metricsBuffer.size();
    }

    public WriteBuffer<MetricsSnapshot> getMetricsBuffer() {
        return metricsBuffer;
    }
}
