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

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.model.DownloadJob;

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

@Slf4j
@Service
@RequiredArgsConstructor
public class DownloadCompressionMessageReceiver {

    public static final String DOWNLOAD_COMPRESSION_LISTENER_ID = "download-compression-listener";

    private final DownloadCompressingService downloadCompressingService;
    private final ObjectMapper objectMapper;


    @SneakyThrows
    @RabbitHandler
    @RabbitListener(id = DOWNLOAD_COMPRESSION_LISTENER_ID)
    public void receive(DownloadJob downloadJob) throws JsonProcessingException {

        downloadCompressingService.compressDownload(downloadJob.getStorageId());

    }

}
