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

import com.fasterxml.jackson.annotation.JsonProperty;

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

@Getter
@EqualsAndHashCode
@Builder
public class SpotifyChart {
    @JsonProperty("chart_id")
    private String chartId;

    @JsonProperty("name")
    private String name;

    @JsonProperty("total_positions")
    private Integer totalPositions;

    @JsonProperty("country_code")
    private String countryCode;

    @JsonProperty("type")
    private SpotifyChartType type;

    @JsonProperty("breakdown")
    private SpotifyChartBreakdown breakdown;

    @JsonProperty("rank")
    private Integer rank;

    public static SpotifyChart of(SpotifyChartEntity entity) {
        if (entity == null) {
            return null;
        }

        return SpotifyChart.builder()
            .chartId(entity.getSpotifyChartId())
            .name(entity.getName())
            .totalPositions(entity.getTotalPositions())
            .countryCode(entity.getSpotifyCountryId())
            .type(entity.getType())
            .breakdown(entity.getBreakdown())
            .rank(entity.getMarketRank().getRank())
            .build();
    }
}
