package com.infinite.focus.server.moods;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;

import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.infinite.focus.server.resourcelibrary.Post;

@Entity
@JsonIgnoreProperties({ "hibernateLazyInitializer", "handler" })
public class Mood {

	// PK
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private long mood_id;

	private String mood;

	private String image;

	private String animated_image;

	private double weight;
	
	@ManyToMany(targetEntity = Post.class, fetch = FetchType.LAZY, cascade = {CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH})
	@JoinTable(name = "post_mood", joinColumns = @JoinColumn(name = "mood_id"), inverseJoinColumns = @JoinColumn(name = "post_id"))
	@JsonIgnore
	private Set<Post> posts = new HashSet<>();

	@Column(name = "created_at", nullable = false)
	@CreationTimestamp
	public Date createdAt;

	@Column(name = "updated_at")
	@UpdateTimestamp
	public Date updatedAt;

	public Mood() {
		super();
	}

	public long getMood_id() {
		return mood_id;
	}

	public void setMood_id(long mood_id) {
		this.mood_id = mood_id;
	}

	public String getMood() {
		return mood;
	}

	public void setMood(String mood) {
		this.mood = mood;
	}

	public String getImage() {
		return image;
	}

	public void setImage(String image) {
		this.image = image;
	}

	public String getAnimated_image() {
		return animated_image;
	}

	public void setAnimated_image(String animated_image) {
		this.animated_image = animated_image;
	}

	public double getWeight() {
		return weight;
	}

	public void setWeight(double weight) {
		this.weight = weight;
	}

	public Set<Post> getPosts() {
		return posts;
	}

	public void setPosts(Set<Post> posts) {
		this.posts = posts;
	}

	public Date getCreatedAt() {
		return createdAt;
	}

	public void setCreatedAt(Date createdAt) {
		this.createdAt = createdAt;
	}

	public Date getUpdatedAt() {
		return updatedAt;
	}

	public void setUpdateAt(Date updatedAt) {
		this.updatedAt = updatedAt;
	}
}
