package io.delphiplatform.api.v3.bigtable;

import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.CompletableFuture;

import javax.transaction.NotSupportedException;

import io.delphiplatform.api.util.model.ModelUtils;
import io.delphiplatform.api.v3.model.Popularity;
import io.delphiplatform.api.v3.view.util.Params;

@Service
public class BigtablePopularityService {

    private final BigtableChartmetricService chartmetricService;

    public BigtablePopularityService(
        BigtableChartmetricService chartmetricService) {
        this.chartmetricService = chartmetricService;
    }

    public CompletableFuture<List<Popularity>> getPopularityModels(Params params)
        throws NotSupportedException {
        return chartmetricService.getModels(params)
            .thenApply(artistFollowers -> ModelUtils.map(artistFollowers, af -> new Popularity()
                .artistId(af.getArtistId())
                .date(af.getDate())
                .spotifyPopularity(af.getSpotifyPopularity())));
    }

}
