package at.procon.dip.ingestion.adapter;

import at.procon.dip.ingestion.dto.ImportedDocumentResult;
import at.procon.dip.ingestion.service.GenericDocumentImportService;
import at.procon.dip.ingestion.spi.DocumentIngestionAdapter;
import at.procon.dip.ingestion.spi.IngestionResult;
import at.procon.dip.ingestion.spi.SourceDescriptor;
import java.util.List;

import at.procon.dip.runtime.condition.ConditionalOnRuntimeMode;
import at.procon.dip.runtime.config.RuntimeMode;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
@ConditionalOnRuntimeMode(RuntimeMode.NEW)
public class FileSystemDocumentIngestionAdapter implements DocumentIngestionAdapter {

    private final GenericDocumentImportService importService;

    @Override
    public boolean supports(SourceDescriptor sourceDescriptor) {
        return sourceDescriptor.sourceType() == at.procon.dip.domain.document.SourceType.FILE_SYSTEM;
    }

    @Override
    public IngestionResult ingest(SourceDescriptor sourceDescriptor) {
        ImportedDocumentResult imported = importService.importDocument(sourceDescriptor);
        return new IngestionResult(List.of(imported.document().toCanonicalMetadata()), imported.warnings());
    }
}
