package io.delphiplatform.api.v3.view;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

import io.delphiplatform.api.v3.constant.DspConstants;
import io.delphiplatform.api.v3.model.datahealth.DspDataImportReport;
import io.delphiplatform.api.v3.model.spotify.LatestJunoSpotifyStreamsResults;
import io.delphiplatform.api.v3.rdb.service.spotify.SpotifyJunoStreamsDataHealthService;
import io.delphiplatform.api.v3.rdb.service.spotify.SpotifyJunoStreamsService;
import io.delphiplatform.api.v3.view.util.Params;
import lombok.NonNull;

@RestController
@RequestMapping("${spring.data.rest.base-path:/v3}")
public class JunoSpotifyApiController implements JunoSpotifyApi {

    private final SpotifyJunoStreamsService spotifyJunoStreamsService;
    private final SpotifyJunoStreamsDataHealthService spotifyJunoDataHealthService;

    @Autowired
    public JunoSpotifyApiController(
        SpotifyJunoStreamsService spotifyJunoStreamsService,
        SpotifyJunoStreamsDataHealthService spotifyJunoDataHealthService
    ) {
        this.spotifyJunoStreamsService = spotifyJunoStreamsService;
        this.spotifyJunoDataHealthService = spotifyJunoDataHealthService;
    }

    @Override
    public ResponseEntity<LatestJunoSpotifyStreamsResults> getLatestJunoSpotifyStreams(@NonNull Params params) {
        return ResponseEntity.ok(new LatestJunoSpotifyStreamsResults(
            spotifyJunoStreamsService.findJunoSpotifyTopStreamsMetrics(params)
        ));
    }

    @Override
    public ResponseEntity<DspDataImportReport> getJunoSpotifyDataStatusDaily() {
        DspDataImportReport report = new DspDataImportReport(new HashMap<>());
        report.getDsp().put(DspConstants.SPOTIFY, spotifyJunoDataHealthService.getLastJunoSpotifyDataHealthReport());

        return ResponseEntity.ok(report);
    }
}
