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

import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Service;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.iqser.red.service.persistence.management.v1.processor.configuration.MessagingConfiguration;
import com.iqser.red.service.persistence.management.v1.processor.model.DownloadJob;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Service
@RequiredArgsConstructor
@RabbitListener(queues = MessagingConfiguration.EXPORT_DOWNLOAD_QUEUE)
public class ExportDownloadMessageReceiver {

    private final DossierTemplateExportService dossierTemplateService;


    @RabbitHandler
    public void receive(DownloadJob downloadJob) throws JsonProcessingException {

        log.info("Preparing export download for userId: {} and storageId: {}", downloadJob.getUserId(), downloadJob.getStorageId());

        dossierTemplateService.createDownloadArchive(downloadJob);
    }

}
