package org.faudroids.myadvent.api;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.io.Serializable;

/**
 * Photo data.
 */
@JsonIgnoreProperties(ignoreUnknown = true)
public class Photo implements Serializable {

	private final String originalFileName, thumbnailFileName;
	private final PhotoDimensions originalDimensions, thumbnailDimensions;
	private final String dominantColor;

	@JsonCreator
	public Photo(
			@JsonProperty("originalFileName") String originalFileName,
			@JsonProperty("originalDimensions") PhotoDimensions originalDimensions,
			@JsonProperty("thumbnailFileName") String thumbnailFileName,
			@JsonProperty("thumbnailDimensions") PhotoDimensions thumbnailDimensions,
			@JsonProperty("dominantColor") String dominantColor) {

		this.originalFileName = originalFileName;
		this.originalDimensions = originalDimensions;
		this.thumbnailFileName = thumbnailFileName;
		this.thumbnailDimensions = thumbnailDimensions;
		this.dominantColor = dominantColor;
	}

	public String getOriginalFileName() {
		return originalFileName;
	}

	public String getThumbnailFileName() {
		return thumbnailFileName;
	}

	public PhotoDimensions getOriginalDimensions() {
		return originalDimensions;
	}

	public PhotoDimensions getThumbnailDimensions() {
		return thumbnailDimensions;
	}

	public String getDominantColor() {
		return dominantColor;
	}

	@Override
	public boolean equals(Object o) {
		if (this == o) return true;
		if (!(o instanceof Photo)) return false;

		Photo photo = (Photo) o;

		if (originalFileName != null ? !originalFileName.equals(photo.originalFileName) : photo.originalFileName != null)
			return false;
		if (thumbnailFileName != null ? !thumbnailFileName.equals(photo.thumbnailFileName) : photo.thumbnailFileName != null)
			return false;
		if (originalDimensions != null ? !originalDimensions.equals(photo.originalDimensions) : photo.originalDimensions != null)
			return false;
		if (thumbnailDimensions != null ? !thumbnailDimensions.equals(photo.thumbnailDimensions) : photo.thumbnailDimensions != null)
			return false;
		return !(dominantColor != null ? !dominantColor.equals(photo.dominantColor) : photo.dominantColor != null);

	}

	@Override
	public int hashCode() {
		int result = originalFileName != null ? originalFileName.hashCode() : 0;
		result = 31 * result + (thumbnailFileName != null ? thumbnailFileName.hashCode() : 0);
		result = 31 * result + (originalDimensions != null ? originalDimensions.hashCode() : 0);
		result = 31 * result + (thumbnailDimensions != null ? thumbnailDimensions.hashCode() : 0);
		result = 31 * result + (dominantColor != null ? dominantColor.hashCode() : 0);
		return result;
	}
}
