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

import static com.knecon.fforesight.service.layoutparser.internal.api.queue.LayoutParsingQueueNames.LAYOUT_PARSING_DLQ;
import static com.knecon.fforesight.service.layoutparser.internal.api.queue.LayoutParsingQueueNames.LAYOUT_PARSING_FINISHED_EVENT_QUEUE;
import static com.knecon.fforesight.service.layoutparser.internal.api.queue.LayoutParsingQueueNames.LAYOUT_PARSING_REQUEST_QUEUE;

import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.QueueBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import lombok.RequiredArgsConstructor;

@Configuration
@RequiredArgsConstructor
public class MessagingConfiguration {

    public static final String REDACTION_QUEUE = "redactionQueue";
    public static final String REDACTION_PRIORITY_QUEUE = "redactionPriorityQueue";
    public static final String REDACTION_DQL = "redactionDQL";

    public static final String DOWNLOAD_QUEUE = "downloadQueue";
    public static final String DOWNLOAD_DLQ = "downloadDLQ";

    public static final String EXPORT_DOWNLOAD_QUEUE = "exportDownloadQueue";
    public static final String EXPORT_DOWNLOAD_DLQ = "exportDownloadDLQ";

    public static final String REPORT_QUEUE = "reportQueue";
    public static final String REPORT_DLQ = "reportDLQ";

    public static final String REPORT_RESULT_QUEUE = "reportResultQueue";
    public static final String REPORT_RESULT_DLQ = "reportResultDLQ";

    public static final String OCR_QUEUE = "ocrQueue";
    public static final String OCR_DLQ = "ocrDLQ";

    public static final String INDEXING_QUEUE = "indexingQueue";
    public static final String INDEXING_DQL = "indexingDQL";

    public static final String DELETE_FROM_INDEX_QUEUE = "deleteFromIndexQueue";
    public static final String DELETE_FROM_INDEX_DLQ = "deleteFromIndexDLQ";

    public static final String IMAGE_SERVICE_QUEUE = "image_request_queue";
    public static final String IMAGE_SERVICE_RESPONSE_QUEUE = "image_response_queue";
    public static final String IMAGE_SERVICE_DLQ = "image_dead_letter_queue";

    public static final String NER_SERVICE_QUEUE = "entity_request_queue";
    public static final String NER_SERVICE_RESPONSE_QUEUE = "entity_response_queue";
    public static final String NER_SERVICE_DLQ = "entity_dead_letter_queue";

    public static final String PRE_PROCESSING_QUEUE = "preprocessingQueue";
    public static final String PRE_PROCESSING_DLQ = "preprocessingDLQ";

    public static final String PDFTRON_QUEUE = "pdftron_queue";
    public static final String PDFTRON_DLQ = "pdftron_dlq";
    public static final String PDFTRON_RESULT_QUEUE = "pdftron_result_queue";

    public static final String CV_ANALYSIS_QUEUE = "cv_analysis_request_queue";
    public static final String CV_ANALYSIS_RESPONSE_QUEUE = "cv_analysis_response_queue";
    public static final String CV_ANALYSIS_DLQ = "cv_analysis_dead_letter_queue";

    public static final String OCR_STATUS_UPDATE_RESPONSE_QUEUE = "ocr_status_update_response_queue";
    public static final String OCR_STATUS_UPDATE_RESPONSE_DQL = "ocr_status_update_response_dql";

    public static final String X_ERROR_INFO_HEADER = "x-error-message";
    public static final String X_ERROR_INFO_TIMESTAMP_HEADER = "x-error-message-timestamp";

    @Bean
    public Queue nerRequestQueue() {

        return QueueBuilder.durable(NER_SERVICE_QUEUE).withArgument("x-dead-letter-exchange", "").withArgument("x-dead-letter-routing-key", NER_SERVICE_DLQ).build();
    }


    @Bean
    public Queue nerResponseQueue() {

        return QueueBuilder.durable(NER_SERVICE_RESPONSE_QUEUE).withArgument("x-dead-letter-exchange", "").withArgument("x-dead-letter-routing-key", NER_SERVICE_DLQ).build();
    }


    @Bean
    public Queue nerResponseDLQ() {

        return QueueBuilder.durable(NER_SERVICE_DLQ).build();
    }


    @Bean
    public Queue imageRequestQueue() {

        return QueueBuilder.durable(IMAGE_SERVICE_QUEUE).withArgument("x-dead-letter-exchange", "").withArgument("x-dead-letter-routing-key", IMAGE_SERVICE_DLQ).build();
    }


    @Bean
    public Queue imageResponseQueue() {

        return QueueBuilder.durable(IMAGE_SERVICE_RESPONSE_QUEUE).withArgument("x-dead-letter-exchange", "").withArgument("x-dead-letter-routing-key", IMAGE_SERVICE_DLQ).build();
    }


    @Bean
    public Queue imageResponseDLQ() {

        return QueueBuilder.durable(IMAGE_SERVICE_DLQ).build();
    }


    @Bean
    public Queue cvAnalysisRequestQueue() {

        return QueueBuilder.durable(CV_ANALYSIS_QUEUE).withArgument("x-dead-letter-exchange", "").withArgument("x-dead-letter-routing-key", CV_ANALYSIS_DLQ).build();
    }


    @Bean
    public Queue cvAnalysisResponseQueue() {

        return QueueBuilder.durable(CV_ANALYSIS_RESPONSE_QUEUE).withArgument("x-dead-letter-exchange", "").withArgument("x-dead-letter-routing-key", CV_ANALYSIS_DLQ).build();
    }


    @Bean
    public Queue cvAnalysisResponseDLQ() {

        return QueueBuilder.durable(CV_ANALYSIS_DLQ).build();
    }


    @Bean
    public Queue ocrStatusUpdateResponseQueue() {

        return QueueBuilder.durable(OCR_STATUS_UPDATE_RESPONSE_QUEUE)
                .withArgument("x-dead-letter-exchange", "")
                .withArgument("x-dead-letter-routing-key", OCR_STATUS_UPDATE_RESPONSE_DQL)
                .build();
    }


    @Bean
    public Queue ocrStatusUpdateResponseDQL() {

        return QueueBuilder.durable(OCR_STATUS_UPDATE_RESPONSE_DQL).build();
    }


    @Bean
    public Queue redactionQueue() {

        return QueueBuilder.durable(REDACTION_QUEUE).withArgument("x-dead-letter-exchange", "").withArgument("x-dead-letter-routing-key", REDACTION_DQL).maxPriority(2).build();
    }


    @Bean
    public Queue redactionPriorityQueue() {

        return QueueBuilder.durable(REDACTION_PRIORITY_QUEUE)
                .withArgument("x-dead-letter-exchange", "")
                .withArgument("x-dead-letter-routing-key", REDACTION_DQL)
                .maxPriority(2)
                .build();
    }


    @Bean
    public Queue ocrQueue() {

        return QueueBuilder.durable(OCR_QUEUE)
                .withArgument("x-dead-letter-exchange", "")
                .withArgument("x-dead-letter-routing-key", OCR_DLQ)
                .withArgument("x-max-priority", 2) // Higher value is higher priority.
                .maxPriority(2)
                .build();
    }


    @Bean
    public Queue downloadQueue() {

        return QueueBuilder.durable(DOWNLOAD_QUEUE).withArgument("x-dead-letter-exchange", "").withArgument("x-dead-letter-routing-key", DOWNLOAD_DLQ).build();
    }


    @Bean
    public Queue downloadDeadLetterQueue() {

        return QueueBuilder.durable(DOWNLOAD_DLQ).build();
    }


    @Bean
    public Queue exportDownloadQueue() {

        return QueueBuilder.durable(EXPORT_DOWNLOAD_QUEUE).withArgument("x-dead-letter-exchange", "").withArgument("x-dead-letter-routing-key", EXPORT_DOWNLOAD_DLQ).build();
    }


    @Bean
    public Queue exportDownloadDeadLetterQueue() {

        return QueueBuilder.durable(EXPORT_DOWNLOAD_DLQ).build();
    }


    @Bean
    public Queue reportQueue() {

        return QueueBuilder.durable(REPORT_QUEUE)
                .withArgument("x-dead-letter-exchange", "")
                .withArgument("x-dead-letter-routing-key", REPORT_DLQ)
                .withArgument("x-max-priority", 2)
                .maxPriority(2)
                .build();
    }


    @Bean
    public Queue reportDeadLetterQueue() {

        return QueueBuilder.durable(REPORT_DLQ).build();
    }


    @Bean
    public Queue reportResultQueue() {

        return QueueBuilder.durable(REPORT_RESULT_QUEUE).withArgument("x-dead-letter-exchange", "").withArgument("x-dead-letter-routing-key", REPORT_RESULT_DLQ).build();
    }


    @Bean
    public Queue reportResultDeadLetterQueue() {

        return QueueBuilder.durable(REPORT_RESULT_DLQ).build();
    }


    @Bean
    public Queue indexingQueue() {

        return QueueBuilder.durable(INDEXING_QUEUE).withArgument("x-dead-letter-exchange", "").withArgument("x-dead-letter-routing-key", INDEXING_DQL).maxPriority(2).build();
    }


    @Bean
    public Queue indexingDeadLetterQueue() {

        return QueueBuilder.durable(INDEXING_DQL).build();
    }


    @Bean
    public Queue deleteFromIndexQueue() {

        return QueueBuilder.durable(DELETE_FROM_INDEX_QUEUE)
                .withArgument("x-dead-letter-exchange", "")
                .withArgument("x-dead-letter-routing-key", DELETE_FROM_INDEX_DLQ)
                .maxPriority(2)
                .build();
    }


    @Bean
    public Queue deleteFromIndexDLQ() {

        return QueueBuilder.durable(DELETE_FROM_INDEX_DLQ).build();
    }


    @Bean
    public Queue preprocessingQueue() {

        return QueueBuilder.durable(PRE_PROCESSING_QUEUE)
                .withArgument("x-dead-letter-exchange", "")
                .withArgument("x-dead-letter-routing-key", PRE_PROCESSING_DLQ)
                .withArgument("x-max-priority", 2)
                .maxPriority(2)
                .build();
    }


    @Bean
    public Queue preprocessingDeadLetterQueue() {

        return QueueBuilder.durable(PRE_PROCESSING_DLQ).build();
    }


    @Bean
    public Queue pdfTronQueue() {

        return QueueBuilder.durable(PDFTRON_QUEUE)
                .withArgument("x-dead-letter-exchange", "")
                .withArgument("x-dead-letter-routing-key", PDFTRON_DLQ)
                .withArgument("x-max-priority", 2)
                .maxPriority(2)
                .build();
    }


    @Bean
    public Queue pdfTronDlq() {

        return QueueBuilder.durable(PDFTRON_DLQ).build();
    }


    @Bean
    public Queue pdfTronResultQueue() {

        return QueueBuilder.durable(PDFTRON_RESULT_QUEUE)
                .withArgument("x-dead-letter-exchange", "")
                .withArgument("x-dead-letter-routing-key", PDFTRON_DLQ)
                .withArgument("x-max-priority", 2)
                .maxPriority(2)
                .build();
    }

    @Bean
    public Queue layoutparsingRequestQueue() {

        return QueueBuilder.durable(LAYOUT_PARSING_REQUEST_QUEUE)//
                .withArgument("x-dead-letter-exchange", "").withArgument("x-dead-letter-routing-key", LAYOUT_PARSING_DLQ).build();
    }


    @Bean
    public Queue layoutparsingResponseQueue() {

        return QueueBuilder.durable(LAYOUT_PARSING_FINISHED_EVENT_QUEUE)//
                .withArgument("x-dead-letter-exchange", "").withArgument("x-dead-letter-routing-key", LAYOUT_PARSING_DLQ).build();
    }


    @Bean
    public Queue layoutparsingDLQ() {

        return QueueBuilder.durable(LAYOUT_PARSING_DLQ).build();
    }
}
