package at.procon.ted.config;

import org.apache.camel.spi.IdempotentRepository;
import org.apache.camel.support.processor.idempotent.FileIdempotentRepository;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.File;

/**
 * Camel configuration beans.
 *
 * @author Martin.Schweitzer@procon.co.at and claude.ai
 */
@Configuration
public class CamelConfig {

    @Value("${ted.solution-brief.idempotent-repository:./solution-brief-processed.dat}")
    private String idempotentRepositoryPath;

    /**
     * File-based idempotent repository for tracking processed files.
     */
    @Bean
    public IdempotentRepository fileIdempotentRepository() {
        File repoFile = new File(idempotentRepositoryPath);
        // Ensure parent directory exists
        if (repoFile.getParentFile() != null && !repoFile.getParentFile().exists()) {
            repoFile.getParentFile().mkdirs();
        }
        return FileIdempotentRepository.fileIdempotentRepository(repoFile, 10000);
    }
}
