package com.iqser.red.service.persistence.management.v1.processor.migration.migrations;

import java.util.List;

import org.springframework.amqp.core.AmqpAdmin;
import org.springframework.stereotype.Service;

import com.iqser.red.service.persistence.management.v1.processor.migration.Migration;

import lombok.Setter;
import lombok.extern.slf4j.Slf4j;


@Slf4j
@Setter
@Service
public class V27QueueRenameMigration extends Migration {

    private final AmqpAdmin amqpAdmin;

    private static final String NAME = "Migration for renaming of most queues";
    private static final long VERSION = 27;
    private static final List<String> queueNames = List.of("analysis_flag_calculation_queue",
                                                           "cv_analysis_dead_letter_queue",
                                                           "cv_analysis_request_queue",
                                                           "cv_analysis_response_queue",
                                                           "deleteFromIndexDLQ",
                                                           "deleteFromIndexQueue",
                                                           "downloadDLQ",
                                                           "downloadQueue",
                                                           "download_compression_dlq",
                                                           "download_compression_queue",
                                                           "entity_dead_letter_queue",
                                                           "entity_request_queue",
                                                           "entity_response_queue",
                                                           "exportDownloadDLQ",
                                                           "exportDownloadQueue",
                                                           "image_dead_letter_queue",
                                                           "image_request_queue",
                                                           "image_response_queue",
                                                           "indexingDQL",
                                                           "indexingQueue",
                                                           "layout_parsing_dead_letter_queue",
                                                           "layout_parsing_request_queue",
                                                           "layout_parsing_response_queue",
                                                           "migrationDLQ",
                                                           "migrationQueue",
                                                           "migrationResponseQueue",
                                                           "mongo-tenant-created",
                                                           "mongo-tenant-created-dlq",
                                                           "ocr_dead_letter_queue",
                                                           "ocr_request_queue",
                                                           "ocr_response_queue",
                                                           "ocr_status_update_dead_letter_queue",
                                                           "ocr_status_update_response_queue",
                                                           "pdftron_dlq",
                                                           "pdftron_queue",
                                                           "pdftron_result_queue",
                                                           "persistence-service-user-created-queue",
                                                           "persistence-service-user-deleted-queue",
                                                           "persistence-service-user-events-dql",
                                                           "persistence-service-user-own-profile-updated-queue",
                                                           "persistence-service-user-roles-updated-queue",
                                                           "persistence-service-user-status-changed-queue",
                                                           "persistence-service-user-updated-queue",
                                                           "preprocessingDLQ",
                                                           "preprocessingQueue",
                                                           "redactionAnalysisResponseQueue",
                                                           "redactionDQL",
                                                           "redactionPriorityQueue",
                                                           "redactionQueue",
                                                           "reportDLQ",
                                                           "reportQueue",
                                                           "reportResultDLQ",
                                                           "reportResultQueue",
                                                           "tenant-created",
                                                           "tenant-created-dlq",
                                                           "tenant-delete-dlq",
                                                           "tenant-delete-queue",
                                                           "tenant-updated-queue",
                                                           "tenant-updated-dlq",
                                                           "tenant-sync",
                                                           "tenant-sync-dlq",
                                                           "visual_layout_parsing_service_dead_letter_queue",
                                                           "visual_layout_parsing_service_queue",
                                                           "visual_layout_parsing_service_response_queue");


    public V27QueueRenameMigration(AmqpAdmin amqpAdmin) {

        super(NAME, VERSION);
        this.amqpAdmin = amqpAdmin;
    }


    @Override
    protected void migrate() {

        log.info("Migration: Deleting queues...");
        for (String queueName : queueNames) {
            log.info("Migration: Deleting queue {}", queueName);
            amqpAdmin.deleteQueue(queueName);
        }

    }

}
