package io.delphiplatform.api.v3.model;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;

import org.openapitools.jackson.nullable.JsonNullable;

import java.util.Objects;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

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


/**
 * ArtistSimple
 */
@JsonPropertyOrder(alphabetic = true)
public class ArtistSimple {

    @JsonProperty("artist_id")
    private String artistId;

    @JsonProperty("full_name")
    private String fullName;

    @JsonProperty("first_name")
    private JsonNullable<String> firstName = JsonNullable.undefined();

    @JsonProperty("last_name")
    private JsonNullable<String> lastName = JsonNullable.undefined();

    @JsonProperty("spotify_artist_id")
    private JsonNullable<String> spotifyArtistId;

    @JsonProperty("spotify_popularity")
    private JsonNullable<Integer> spotifyPopularity = JsonNullable.undefined();

    @JsonProperty("image")
    private JsonNullable<ImageSimple> image = JsonNullable.undefined();

    @JsonProperty("apple_artist_id")
    private JsonNullable<Integer> appleArtistId;

    public  ArtistSimple () {
    }

    public  ArtistSimple (String artistId) {
        this.artistId = artistId;
    }

    public static ArtistSimple from(ArtistEntity artist, ImageService imageService) {
        if (artist == null) {
            return null;
        }
        return new ArtistSimple()
            .artistId(artist.getArtistId())
            .firstName(artist.getFirstName())
            .lastName(artist.getLastName())
            .fullName(artist.getFullName())
            .appleArtistId(artist.getAppleArtistId())
            .spotifyArtistId(artist.getSpotifyArtistId())
            .image(imageService.resolveImage(artist));
    }

    public ArtistSimple artistId(String artistId) {
        this.artistId = artistId;
        return this;
    }

    /**
     * Primary key identifier for Artist
     *
     * @return artistId
     */
    @NotNull
    public String getArtistId() {
        return artistId;
    }

    public void setArtistId(String artistId) {
        this.artistId = artistId;
    }

    public ArtistSimple fullName(String fullName) {
        this.fullName = fullName;
        return this;
    }

    /**
     * Get fullName
     *
     * @return fullName
     */
    @NotNull
    public String getFullName() {
        return fullName;
    }

    public void setFullName(String fullName) {
        this.fullName = fullName;
    }

    public ArtistSimple firstName(String firstName) {
        this.firstName = JsonNullable.of(firstName);
        return this;
    }

    /**
     * Get firstName
     *
     * @return firstName
     */
    public JsonNullable<String> getFirstName() {
        return firstName;
    }

    public void setFirstName(JsonNullable<String> firstName) {
        this.firstName = firstName;
    }

    public ArtistSimple lastName(String lastName) {
        this.lastName = JsonNullable.of(lastName);
        return this;
    }

    /**
     * Get lastName
     *
     * @return lastName
     */
    public JsonNullable<String> getLastName() {
        return lastName;
    }

    public void setLastName(JsonNullable<String> lastName) {
        this.lastName = lastName;
    }

    public ArtistSimple spotifyArtistId(String spotifyArtistId) {
        this.spotifyArtistId = JsonNullable.of(spotifyArtistId);
        return this;
    }

    /**
     * Get spotifyArtistId
     *
     * @return spotifyArtistId
     */
    @Valid
    public JsonNullable<String> getSpotifyArtistId() {
        return spotifyArtistId;
    }

    public void setSpotifyArtistId(JsonNullable<String> spotifyArtistId) {
        this.spotifyArtistId = spotifyArtistId;
    }

    public ArtistSimple spotifyPopularity(Integer spotifyPopularity) {
        this.spotifyPopularity = JsonNullable.of(spotifyPopularity);
        return this;
    }

    /**
     * The popularity of a track is a value between 0 and 100, with 100 being the most popular. The popularity is
     * calculated by algorithm and is based, in the most part, on the total number of plays the track has had and how
     * recent those plays are. Generally speaking, songs that are being played a lot now will have a higher popularity
     * than songs that were played a lot in the past. Duplicate tracks (e.g. the same track from a single and an
     * product) are rated independently. Artist and album popularity is derived mathematically from track popularity.
     * Note that the popularity value may lag actual popularity by a few days: the value is not updated in real time.
     *
     * @return spotifyPopularity
     */
    public JsonNullable<Integer> getSpotifyPopularity() {
        return spotifyPopularity;
    }

    public void setSpotifyPopularity(JsonNullable<Integer> spotifyPopularity) {
        this.spotifyPopularity = spotifyPopularity;
    }

    public ArtistSimple image(ImageSimple image) {
        this.image = JsonNullable.of(image);
        return this;
    }

    /**
     * Get image
     *
     * @return image
     */
    @Valid
    public JsonNullable<ImageSimple> getImage() {
        return image;
    }

    public void setImage(JsonNullable<ImageSimple> image) {
        this.image = image;
    }

    public JsonNullable<Integer> getAppleArtistId() {
        return appleArtistId;
    }

    public void setAppleArtistId(JsonNullable<Integer> appleArtistId) {
        this.appleArtistId = appleArtistId;
    }

    public ArtistSimple appleArtistId(Integer appleArtistId) {
        this.appleArtistId = JsonNullable.of(appleArtistId);
        return this;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        ArtistSimple artistSimple = (ArtistSimple) o;
        return Objects.equals(this.artistId, artistSimple.artistId) &&
            Objects.equals(this.fullName, artistSimple.fullName) &&
            Objects.equals(this.firstName, artistSimple.firstName) &&
            Objects.equals(this.lastName, artistSimple.lastName) &&
            Objects.equals(this.spotifyArtistId, artistSimple.spotifyArtistId) &&
            Objects.equals(this.spotifyPopularity, artistSimple.spotifyPopularity) &&
            Objects.equals(this.image, artistSimple.image);
    }

    @Override
    public int hashCode() {
        return Objects.hash(artistId, fullName, firstName, lastName, spotifyArtistId, spotifyPopularity, image);
    }

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

        sb.append("    artistId: ").append(toIndentedString(artistId)).append("\n");
        sb.append("    appleArtistId: ").append(toIndentedString(appleArtistId)).append("\n");
        sb.append("    fullName: ").append(toIndentedString(fullName)).append("\n");
        sb.append("    firstName: ").append(toIndentedString(firstName)).append("\n");
        sb.append("    lastName: ").append(toIndentedString(lastName)).append("\n");
        sb.append("    spotifyArtistId: ").append(toIndentedString(spotifyArtistId)).append("\n");
        sb.append("    spotifyPopularity: ").append(toIndentedString(spotifyPopularity)).append("\n");
        sb.append("    image: ").append(toIndentedString(image)).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    ");
    }

}
