package io.delphiplatform.api.v3.rdb.service.spotify;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import io.delphiplatform.api.v3.model.datahealth.DspDataImportReportItem;
import io.delphiplatform.api.v3.rdb.entity.spotify.SpotifyJunoStatusDailyEntity;
import io.delphiplatform.api.v3.rdb.repository.spotify.SpotifyJunoStreamsDataHealthRepository;

@Service
public class SpotifyJunoStreamsDataHealthService {

    private final SpotifyJunoStreamsDataHealthRepository dataHealthRepository;

    @Autowired
    public SpotifyJunoStreamsDataHealthService(
        SpotifyJunoStreamsDataHealthRepository dataHealthRepository
    ) {
        this.dataHealthRepository = dataHealthRepository;
    }

    @Transactional(readOnly = true)
    public DspDataImportReportItem getLastJunoSpotifyDataHealthReport() {
        SpotifyJunoStatusDailyEntity report = dataHealthRepository.findReportByDate(
            dataHealthRepository.findMaxReportDate()
        );

        return DspDataImportReportItem.from(report);
    }
}
