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

import com.fasterxml.jackson.annotation.JsonProperty;

import org.openapitools.jackson.nullable.JsonNullable;

import java.util.Objects;

import io.delphiplatform.api.v3.model.service.ImageService;
import io.delphiplatform.api.v3.rdb.entity.video.FactYoutubeVideoTrendingChartEntity;

/**
 * VideoChartPosition
 */
public class VideoChartPosition {

    @JsonProperty("chart")
    private JsonNullable<VideoChart> chart = JsonNullable.undefined();

    @JsonProperty("position")
    private ChartPosition position;

    @JsonProperty("video_id")
    private String videoId;

    @JsonProperty("video")
    private JsonNullable<Video> video = JsonNullable.undefined();

    public static VideoChartPosition of(FactYoutubeVideoTrendingChartEntity entity, ImageService imageService,
        boolean isVideoIncluded) {
        if (entity == null) {
            return null;
        }
        VideoChartPosition position = new VideoChartPosition()
            .chart(VideoChart.of(entity.getChart()))
            .position(ChartPosition.of(entity))
            .videoId(entity.getVideo() == null ? null : entity.getVideo().getVideoId());
        if (isVideoIncluded) {
            position.video(Video.from(entity.getVideo(), imageService));
        }
        return position;

    }

    public VideoChartPosition chart(VideoChart chart) {
        this.chart = JsonNullable.of(chart);
        return this;
    }

    /**
     * Get chart
     *
     * @return chart
     */
    public JsonNullable<VideoChart> getChart() {
        return chart;
    }

    public void setChart(JsonNullable<VideoChart> chart) {
        this.chart = chart;
    }

    public VideoChartPosition position(ChartPosition position) {
        this.position = position;
        return this;
    }

    /**
     * Get position
     *
     * @return position
     */
    public ChartPosition getPosition() {
        return position;
    }

    public void setPosition(ChartPosition position) {
        this.position = position;
    }

    public VideoChartPosition videoId(String videoId) {
        this.videoId = videoId;
        return this;
    }

    /**
     * Primary key identifier for a Video
     *
     * @return videoId
     */
    public String getVideoId() {
        return videoId;
    }

    public void setVideoId(String videoId) {
        this.videoId = videoId;
    }

    public VideoChartPosition video(Video video) {
        this.video = JsonNullable.of(video);
        return this;
    }

    /**
     * Get video
     *
     * @return video
     */
    public JsonNullable<Video> getVideo() {
        return video;
    }

    public void setVideo(JsonNullable<Video> video) {
        this.video = video;
    }


    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        VideoChartPosition videoChartPosition = (VideoChartPosition) o;
        return Objects.equals(this.chart, videoChartPosition.chart) &&
            Objects.equals(this.position, videoChartPosition.position) &&
            Objects.equals(this.videoId, videoChartPosition.videoId) &&
            Objects.equals(this.video, videoChartPosition.video);
    }

    @Override
    public int hashCode() {
        return Objects.hash(chart, position, videoId, video);
    }

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

        sb.append("    chart: ").append(toIndentedString(chart)).append("\n");
        sb.append("    position: ").append(toIndentedString(position)).append("\n");
        sb.append("    videoId: ").append(toIndentedString(videoId)).append("\n");
        sb.append("    video: ").append(toIndentedString(video)).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    ");
    }
}

