package io.delphiplatform.api.v3.model.spotify;

import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.Arrays;
import java.util.List;

import io.delphiplatform.api.v3.rdb.entity.spotify.SpotifyJunoTopStreamsDailyEntity;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;

@Builder
@Getter
@Setter
@EqualsAndHashCode
public class JunoSpotifyStreamsTrackMeta {
    @JsonProperty("spotify_track_id")
    private String spotifyTrackId;

    @JsonProperty("track_name")
    private String trackName;

    @JsonProperty("artist_names")
    private List<String> artistNames;

    @JsonProperty("track_uri")
    private String trackUri;

    public static JunoSpotifyStreamsTrackMeta from(SpotifyJunoTopStreamsDailyEntity entity) {
        if (entity == null) {
            return null;
        }

        return JunoSpotifyStreamsTrackMeta.builder()
            .spotifyTrackId(entity.getSpotifyTrackId())
            .trackName(entity.getSpotifyTrackName())
            .artistNames(entity.getSpotifyTrackArtists() != null
                ? Arrays.asList(entity.getSpotifyTrackArtists()) : null)
            .trackUri(entity.getSpotifyTrackUri())
            .build();
    }
}
