package com.cameleer.server.app.config;

import com.cameleer.server.core.ingestion.BufferedLogEntry;
import com.cameleer.server.core.ingestion.ChunkAccumulator;
import com.cameleer.server.core.ingestion.MergedExecution;
import com.cameleer.server.core.ingestion.WriteBuffer;
import com.cameleer.server.core.storage.model.MetricsSnapshot;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Creates write buffer beans for the ingestion pipeline.
 * <p>
 * Each {@link WriteBuffer} instance is shared between the
 * {@link com.cameleer.server.core.ingestion.IngestionService} (producer side)
 * and the flush scheduler (consumer side).
 */
@Configuration
public class IngestionBeanConfig {

    @Bean
    public WriteBuffer<MetricsSnapshot> metricsBuffer(IngestionConfig config) {
        return new WriteBuffer<>(config.getBufferCapacity());
    }

    @Bean
    public WriteBuffer<MergedExecution> executionBuffer(IngestionConfig config) {
        return new WriteBuffer<>(config.getBufferCapacity());
    }

    @Bean
    public WriteBuffer<ChunkAccumulator.ProcessorBatch> processorBatchBuffer(IngestionConfig config) {
        return new WriteBuffer<>(config.getBufferCapacity());
    }

    @Bean
    public WriteBuffer<BufferedLogEntry> logBuffer(IngestionConfig config) {
        return new WriteBuffer<>(config.getBufferCapacity());
    }
}
