package com.iqser.red.service.persistence.management.v1.processor.configuration;

import static com.iqser.red.service.persistence.management.v1.processor.configuration.MessagingConfiguration.ANALYSIS_FLAG_CALCULATION_REQUEST_EXCHANGE;
import static com.iqser.red.service.persistence.management.v1.processor.configuration.MessagingConfiguration.ANALYSIS_FLAG_CALCULATION_REQUEST_QUEUE_PREFIX;
import static com.iqser.red.service.persistence.management.v1.processor.configuration.MessagingConfiguration.AZURE_ENTITY_DLQ;
import static com.iqser.red.service.persistence.management.v1.processor.configuration.MessagingConfiguration.AZURE_ENTITY_RESPONSE_EXCHANGE;
import static com.iqser.red.service.persistence.management.v1.processor.configuration.MessagingConfiguration.AZURE_ENTITY_RESPONSE_QUEUE_PREFIX;
import static com.iqser.red.service.persistence.management.v1.processor.configuration.MessagingConfiguration.CHUNKING_DLQ;
import static com.iqser.red.service.persistence.management.v1.processor.configuration.MessagingConfiguration.CHUNKING_RESPONSE_EXCHANGE;
import static com.iqser.red.service.persistence.management.v1.processor.configuration.MessagingConfiguration.CHUNKING_RESPONSE_QUEUE_PREFIX;
import static com.iqser.red.service.persistence.management.v1.processor.configuration.MessagingConfiguration.CV_ANALYSIS_DLQ;
import static com.iqser.red.service.persistence.management.v1.processor.configuration.MessagingConfiguration.CV_ANALYSIS_RESPONSE_EXCHANGE;
import static com.iqser.red.service.persistence.management.v1.processor.configuration.MessagingConfiguration.CV_ANALYSIS_RESPONSE_QUEUE_PREFIX;
import static com.iqser.red.service.persistence.management.v1.processor.configuration.MessagingConfiguration.DOWNLOAD_COMPRESSION_DLQ;
import static com.iqser.red.service.persistence.management.v1.processor.configuration.MessagingConfiguration.DOWNLOAD_COMPRESSION_REQUEST_EXCHANGE;
import static com.iqser.red.service.persistence.management.v1.processor.configuration.MessagingConfiguration.DOWNLOAD_COMPRESSION_REQUEST_QUEUE_PREFIX;
import static com.iqser.red.service.persistence.management.v1.processor.configuration.MessagingConfiguration.DOWNLOAD_DLQ;
import static com.iqser.red.service.persistence.management.v1.processor.configuration.MessagingConfiguration.DOWNLOAD_REQUEST_EXCHANGE;
import static com.iqser.red.service.persistence.management.v1.processor.configuration.MessagingConfiguration.DOWNLOAD_REQUEST_QUEUE_PREFIX;
import static com.iqser.red.service.persistence.management.v1.processor.configuration.MessagingConfiguration.ENTITY_DLQ;
import static com.iqser.red.service.persistence.management.v1.processor.configuration.MessagingConfiguration.ENTITY_RESPONSE_EXCHANGE;
import static com.iqser.red.service.persistence.management.v1.processor.configuration.MessagingConfiguration.ENTITY_RESPONSE_QUEUE_PREFIX;
import static com.iqser.red.service.persistence.management.v1.processor.configuration.MessagingConfiguration.EXPORT_DOWNLOAD_DLQ;
import static com.iqser.red.service.persistence.management.v1.processor.configuration.MessagingConfiguration.EXPORT_DOWNLOAD_REQUEST_EXCHANGE;
import static com.iqser.red.service.persistence.management.v1.processor.configuration.MessagingConfiguration.EXPORT_DOWNLOAD_REQUEST_QUEUE_PREFIX;
import static com.iqser.red.service.persistence.management.v1.processor.configuration.MessagingConfiguration.IMAGE_DLQ;
import static com.iqser.red.service.persistence.management.v1.processor.configuration.MessagingConfiguration.IMAGE_RESPONSE_EXCHANGE;
import static com.iqser.red.service.persistence.management.v1.processor.configuration.MessagingConfiguration.IMAGE_RESPONSE_QUEUE_PREFIX;
import static com.iqser.red.service.persistence.management.v1.processor.configuration.MessagingConfiguration.LLM_NER_DLQ;
import static com.iqser.red.service.persistence.management.v1.processor.configuration.MessagingConfiguration.LLM_NER_RESPONSE_EXCHANGE;
import static com.iqser.red.service.persistence.management.v1.processor.configuration.MessagingConfiguration.LLM_NER_RESPONSE_QUEUE_PREFIX;
import static com.iqser.red.service.persistence.management.v1.processor.configuration.MessagingConfiguration.OCR_RESPONSE_EXCHANGE;
import static com.iqser.red.service.persistence.management.v1.processor.configuration.MessagingConfiguration.OCR_RESPONSE_QUEUE_PREFIX;
import static com.iqser.red.service.persistence.management.v1.processor.configuration.MessagingConfiguration.OCR_STATUS_UPDATE_DLQ;
import static com.iqser.red.service.persistence.management.v1.processor.configuration.MessagingConfiguration.OCR_STATUS_UPDATE_RESPONSE_EXCHANGE;
import static com.iqser.red.service.persistence.management.v1.processor.configuration.MessagingConfiguration.OCR_STATUS_UPDATE_RESPONSE_QUEUE_PREFIX;
import static com.iqser.red.service.persistence.management.v1.processor.configuration.MessagingConfiguration.PDFTRON_DLQ;
import static com.iqser.red.service.persistence.management.v1.processor.configuration.MessagingConfiguration.PDFTRON_RESPONSE_EXCHANGE;
import static com.iqser.red.service.persistence.management.v1.processor.configuration.MessagingConfiguration.PDFTRON_RESPONSE_QUEUE_PREFIX;
import static com.iqser.red.service.persistence.management.v1.processor.configuration.MessagingConfiguration.REDACTION_DLQ;
import static com.iqser.red.service.persistence.management.v1.processor.configuration.MessagingConfiguration.REDACTION_RESPONSE_EXCHANGE;
import static com.iqser.red.service.persistence.management.v1.processor.configuration.MessagingConfiguration.REDACTION_RESPONSE_QUEUE_PREFIX;
import static com.iqser.red.service.persistence.management.v1.processor.configuration.MessagingConfiguration.REPORT_RESPONSE_DLQ;
import static com.iqser.red.service.persistence.management.v1.processor.configuration.MessagingConfiguration.REPORT_RESPONSE_EXCHANGE;
import static com.iqser.red.service.persistence.management.v1.processor.configuration.MessagingConfiguration.REPORT_RESPONSE_QUEUE_PREFIX;
import static com.iqser.red.service.persistence.management.v1.processor.configuration.MessagingConfiguration.SEARCH_BULK_LOCAL_TERM_DLQ;
import static com.iqser.red.service.persistence.management.v1.processor.configuration.MessagingConfiguration.SEARCH_BULK_LOCAL_TERM_RESPONSE_EXCHANGE;
import static com.iqser.red.service.persistence.management.v1.processor.configuration.MessagingConfiguration.SEARCH_BULK_LOCAL_TERM_RESPONSE_QUEUE_PREFIX;
import static com.iqser.red.service.persistence.management.v1.processor.configuration.MessagingConfiguration.VISUAL_LAYOUT_PARSING_DLQ;
import static com.iqser.red.service.persistence.management.v1.processor.configuration.MessagingConfiguration.VISUAL_LAYOUT_PARSING_RESPONSE_EXCHANGE;
import static com.iqser.red.service.persistence.management.v1.processor.configuration.MessagingConfiguration.VISUAL_LAYOUT_PARSING_RESPONSE_QUEUE_PREFIX;
import static com.iqser.red.service.persistence.management.v1.processor.dataexchange.ExportDownloadMessageReceiver.EXPORT_DOWNLOAD_LISTENER_ID;
import static com.iqser.red.service.persistence.management.v1.processor.service.download.DownloadCompressionMessageReceiver.DOWNLOAD_COMPRESSION_LISTENER_ID;
import static com.iqser.red.service.persistence.management.v1.processor.service.download.DownloadMessageReceiver.DOWNLOAD_LISTENER_ID;
import static com.iqser.red.service.persistence.management.v1.processor.service.download.DownloadReportMessageReceiver.REPORT_RESPONSE_LISTENER_ID;
import static com.iqser.red.service.persistence.management.v1.processor.service.download.RedactionResultMessageReceiver.PDFTRON_RESPONSE_LISTENER_ID;
import static com.iqser.red.service.persistence.management.v1.processor.service.queue.AnalysisFlagsCalculationMessageReceiver.ANALYSIS_FLAG_CALCULATION_LISTENER_ID;
import static com.iqser.red.service.persistence.management.v1.processor.service.queue.AzureNerMessageReceiver.AZURE_ENTITY_RESPONSE_LISTENER_ID;
import static com.iqser.red.service.persistence.management.v1.processor.service.queue.ChunkingMessageReceiver.CHUNKING_RESPONSE_LISTENER_ID;
import static com.iqser.red.service.persistence.management.v1.processor.service.queue.CvAnalysisMessageReceiver.CV_ANALYSIS_RESPONSE_LISTENER_ID;
import static com.iqser.red.service.persistence.management.v1.processor.service.queue.ImageMessageReceiver.IMAGE_RESPONSE_LISTENER_ID;
import static com.iqser.red.service.persistence.management.v1.processor.service.queue.LayoutParsingFinishedMessageReceiver.LAYOUT_PARSING_RESPONSE_LISTENER_ID;
import static com.iqser.red.service.persistence.management.v1.processor.service.queue.NerMessageReceiver.ENTITY_RESPONSE_LISTENER_ID;
import static com.iqser.red.service.persistence.management.v1.processor.service.queue.NerMessageReceiver.LLM_ENTITY_RESPONSE_LISTENER_ID;
import static com.iqser.red.service.persistence.management.v1.processor.service.queue.OCRProcessingMessageReceiver.OCR_RESPONSE_LISTENER_ID;
import static com.iqser.red.service.persistence.management.v1.processor.service.queue.OCRProcessingMessageReceiver.OCR_STATUS_UPDATE_LISTENER_ID;
import static com.iqser.red.service.persistence.management.v1.processor.service.queue.RedactionAnalysisResponseReceiver.REDACTION_RESPONSE_LISTENER_ID;
import static com.iqser.red.service.persistence.management.v1.processor.service.queue.SearchTermOccurrencesResponseReceiver.SEARCH_BULK_LOCAL_TERM_RESPONSE_LISTENER;
import static com.iqser.red.service.persistence.management.v1.processor.service.queue.VisualLayoutParsingMessageReceiver.VISUAL_LAYOUT_PARSING_RESPONSE_LISTENER_ID;

import java.util.Map;
import java.util.Set;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.knecon.fforesight.service.layoutparser.internal.api.queue.LayoutParsingQueueNames;
import com.knecon.fforesight.tenantcommons.model.TenantQueueConfiguration;
import com.knecon.fforesight.tenantcommons.model.TenantQueueProvider;

@Configuration
public class QueueProviderConfiguration {

    @Bean
    public TenantQueueProvider tenantQueueProvider() {

        var queues = Set.of(TenantQueueConfiguration.builder()
                        .listenerId(DOWNLOAD_LISTENER_ID)
                        .exchangeName(DOWNLOAD_REQUEST_EXCHANGE)
                        .queuePrefix(DOWNLOAD_REQUEST_QUEUE_PREFIX)
                        .dlqName(DOWNLOAD_DLQ)
                        .build(),
                TenantQueueConfiguration.builder()
                        .listenerId(DOWNLOAD_COMPRESSION_LISTENER_ID)
                        .exchangeName(DOWNLOAD_COMPRESSION_REQUEST_EXCHANGE)
                        .queuePrefix(DOWNLOAD_COMPRESSION_REQUEST_QUEUE_PREFIX)
                        .dlqName(DOWNLOAD_COMPRESSION_DLQ)
                        .build(),
                TenantQueueConfiguration.builder()
                        .listenerId(EXPORT_DOWNLOAD_LISTENER_ID)
                        .exchangeName(EXPORT_DOWNLOAD_REQUEST_EXCHANGE)
                        .queuePrefix(EXPORT_DOWNLOAD_REQUEST_QUEUE_PREFIX)
                        .dlqName(EXPORT_DOWNLOAD_DLQ)
                        .build(),
                TenantQueueConfiguration.builder()
                        .listenerId(ANALYSIS_FLAG_CALCULATION_LISTENER_ID)
                        .exchangeName(ANALYSIS_FLAG_CALCULATION_REQUEST_EXCHANGE)
                        .queuePrefix(ANALYSIS_FLAG_CALCULATION_REQUEST_QUEUE_PREFIX)
                        .build(),
                TenantQueueConfiguration.builder()
                        .listenerId(REDACTION_RESPONSE_LISTENER_ID)
                        .exchangeName(REDACTION_RESPONSE_EXCHANGE)
                        .queuePrefix(REDACTION_RESPONSE_QUEUE_PREFIX)
                        .dlqName(REDACTION_DLQ)
                        .arguments(Map.of("x-max-priority", 2))
                        .build(),
                TenantQueueConfiguration.builder()
                        .listenerId(SEARCH_BULK_LOCAL_TERM_RESPONSE_LISTENER)
                        .exchangeName(SEARCH_BULK_LOCAL_TERM_RESPONSE_EXCHANGE)
                        .queuePrefix(SEARCH_BULK_LOCAL_TERM_RESPONSE_QUEUE_PREFIX)
                        .dlqName(SEARCH_BULK_LOCAL_TERM_DLQ)
                        .arguments(Map.of("x-max-priority", 2))
                        .build(),
                TenantQueueConfiguration.builder()
                        .listenerId(PDFTRON_RESPONSE_LISTENER_ID)
                        .exchangeName(PDFTRON_RESPONSE_EXCHANGE)
                        .queuePrefix(PDFTRON_RESPONSE_QUEUE_PREFIX)
                        .dlqName(PDFTRON_DLQ)
                        .arguments(Map.of("x-max-priority", 2))
                        .build(),
                TenantQueueConfiguration.builder()
                        .listenerId(REPORT_RESPONSE_LISTENER_ID)
                        .exchangeName(REPORT_RESPONSE_EXCHANGE)
                        .queuePrefix(REPORT_RESPONSE_QUEUE_PREFIX)
                        .dlqName(REPORT_RESPONSE_DLQ)
                        .build(),
                TenantQueueConfiguration.builder()
                        .listenerId(OCR_RESPONSE_LISTENER_ID)
                        .exchangeName(OCR_RESPONSE_EXCHANGE)
                        .queuePrefix(OCR_RESPONSE_QUEUE_PREFIX)
                        .build(),
                TenantQueueConfiguration.builder()
                        .listenerId(OCR_STATUS_UPDATE_LISTENER_ID)
                        .exchangeName(OCR_STATUS_UPDATE_RESPONSE_EXCHANGE)
                        .queuePrefix(OCR_STATUS_UPDATE_RESPONSE_QUEUE_PREFIX)
                        .dlqName(OCR_STATUS_UPDATE_DLQ)
                        .build(),
                TenantQueueConfiguration.builder()
                        .listenerId(IMAGE_RESPONSE_LISTENER_ID)
                        .exchangeName(IMAGE_RESPONSE_EXCHANGE)
                        .queuePrefix(IMAGE_RESPONSE_QUEUE_PREFIX)
                        .dlqName(IMAGE_DLQ)
                        .build(),
                TenantQueueConfiguration.builder()
                        .listenerId(ENTITY_RESPONSE_LISTENER_ID)
                        .exchangeName(ENTITY_RESPONSE_EXCHANGE)
                        .queuePrefix(ENTITY_RESPONSE_QUEUE_PREFIX)
                        .dlqName(ENTITY_DLQ)
                        .build(),
                TenantQueueConfiguration.builder()
                        .listenerId(AZURE_ENTITY_RESPONSE_LISTENER_ID)
                        .exchangeName(AZURE_ENTITY_RESPONSE_EXCHANGE)
                        .queuePrefix(AZURE_ENTITY_RESPONSE_QUEUE_PREFIX)
                        .dlqName(AZURE_ENTITY_DLQ)
                        .build(),
                TenantQueueConfiguration.builder()
                        .listenerId(CHUNKING_RESPONSE_LISTENER_ID)
                        .exchangeName(CHUNKING_RESPONSE_EXCHANGE)
                        .queuePrefix(CHUNKING_RESPONSE_QUEUE_PREFIX)
                        .dlqName(CHUNKING_DLQ)
                        .build(),
                TenantQueueConfiguration.builder()
                        .listenerId(LLM_ENTITY_RESPONSE_LISTENER_ID)
                        .exchangeName(LLM_NER_RESPONSE_EXCHANGE)
                        .queuePrefix(LLM_NER_RESPONSE_QUEUE_PREFIX)
                        .dlqName(LLM_NER_DLQ)
                        .build(),
                TenantQueueConfiguration.builder()
                        .listenerId(CV_ANALYSIS_RESPONSE_LISTENER_ID)
                        .exchangeName(CV_ANALYSIS_RESPONSE_EXCHANGE)
                        .queuePrefix(CV_ANALYSIS_RESPONSE_QUEUE_PREFIX)
                        .dlqName(CV_ANALYSIS_DLQ)
                        .build(),
                TenantQueueConfiguration.builder()
                        .listenerId(VISUAL_LAYOUT_PARSING_RESPONSE_LISTENER_ID)
                        .exchangeName(VISUAL_LAYOUT_PARSING_RESPONSE_EXCHANGE)
                        .queuePrefix(VISUAL_LAYOUT_PARSING_RESPONSE_QUEUE_PREFIX)
                        .dlqName(VISUAL_LAYOUT_PARSING_DLQ)
                        .build(),
                TenantQueueConfiguration.builder()
                        .listenerId(LAYOUT_PARSING_RESPONSE_LISTENER_ID)
                        .exchangeName(LayoutParsingQueueNames.LAYOUT_PARSING_RESPONSE_EXCHANGE)
                        .queuePrefix(LayoutParsingQueueNames.LAYOUT_PARSING_RESPONSE_QUEUE_PREFIX)
                        .build());
        return new TenantQueueProvider(queues);
    }

}
