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

import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.Objects;

import io.delphiplatform.api.v3.rdb.entity.ChartEntity;

/**
 * VideoChart
 */
public class VideoChart {

    @JsonProperty("chart_id")
    private String chartId;

    @JsonProperty("name")
    private String name;

    @JsonProperty("chart_group")
    private VideoChartGroup chartGroup;

    @JsonProperty("country_code")
    private String countryCode;

    @JsonProperty("dsp")
    private VideoDspSlug dsp;

    @JsonProperty("total_positions")
    private Integer totalPositions;

    public static VideoChart of(ChartEntity entity){
        if(entity == null){
            return null;
        }
        return new VideoChart()
            .chartId(entity.getChartId())
            .name(entity.getName())
            .chartGroup(VideoChartGroup.fromValue(entity.getChartGroup()))
            .countryCode(entity.getCountryCode() == null ? null : entity.getCountryCode().getCountryCode())
            .dsp(entity.getDsp() == null ? null :  VideoDspSlug.fromValue(entity.getDsp().getDspId()))
            .totalPositions(entity.getNumTracks());
    }

    public VideoChart chartId(String chartId) {
        this.chartId = chartId;
        return this;
    }

    /**
     * Unique identifier for a Video Chart.
     *
     * @return chartId
     */
    public String getChartId() {
        return chartId;
    }

    public void setChartId(String chartId) {
        this.chartId = chartId;
    }

    public VideoChart name(String name) {
        this.name = name;
        return this;
    }

    /**
     * The human-friendly (nice name) of the Chart.
     *
     * @return name
     */
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public VideoChart chartGroup(VideoChartGroup chartGroup) {
        this.chartGroup = chartGroup;
        return this;
    }

    /**
     * Get chartGroup
     *
     * @return chartGroup
     */
    public VideoChartGroup getChartGroup() {
        return chartGroup;
    }

    public void setChartGroup(VideoChartGroup chartGroup) {
        this.chartGroup = chartGroup;
    }

    public VideoChart countryCode(String countryCode) {
        this.countryCode = countryCode;
        return this;
    }

    /**
     * Typically a lower-case two letter code for the country
     *
     * @return countryCode
     */
    public String getCountryCode() {
        return countryCode;
    }

    public void setCountryCode(String countryCode) {
        this.countryCode = countryCode;
    }

    public VideoChart dsp(VideoDspSlug dsp) {
        this.dsp = dsp;
        return this;
    }

    /**
     * Get dsp
     *
     * @return dsp
     */
    public VideoDspSlug getDsp() {
        return dsp;
    }

    public void setDsp(VideoDspSlug dsp) {
        this.dsp = dsp;
    }

    public VideoChart totalPositions(Integer totalPositions) {
        this.totalPositions = totalPositions;
        return this;
    }

    /**
     * Total number of items supported by the Chart or Playlist.
     *
     * @return totalPositions
     */
    public Integer getTotalPositions() {
        return totalPositions;
    }

    public void setTotalPositions(Integer totalPositions) {
        this.totalPositions = totalPositions;
    }


    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        VideoChart videoChart = (VideoChart) o;
        return Objects.equals(this.chartId, videoChart.chartId) &&
            Objects.equals(this.name, videoChart.name) &&
            Objects.equals(this.chartGroup, videoChart.chartGroup) &&
            Objects.equals(this.countryCode, videoChart.countryCode) &&
            Objects.equals(this.dsp, videoChart.dsp) &&
            Objects.equals(this.totalPositions, videoChart.totalPositions);
    }

    @Override
    public int hashCode() {
        return Objects.hash(chartId, name, chartGroup, countryCode, dsp, totalPositions);
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("class VideoChart {\n");

        sb.append("    chartId: ").append(toIndentedString(chartId)).append("\n");
        sb.append("    name: ").append(toIndentedString(name)).append("\n");
        sb.append("    chartGroup: ").append(toIndentedString(chartGroup)).append("\n");
        sb.append("    countryCode: ").append(toIndentedString(countryCode)).append("\n");
        sb.append("    dsp: ").append(toIndentedString(dsp)).append("\n");
        sb.append("    totalPositions: ").append(toIndentedString(totalPositions)).append("\n");
        sb.append("}");
        return sb.toString();
    }

    /**
     * Convert the given object to string with each line indented by 4 spaces (except the first line).
     */
    private String toIndentedString(Object o) {
        if (o == null) {
            return "null";
        }
        return o.toString().replace("\n", "\n    ");
    }
}

