package eu.dnetlib.goldoa.domain;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.google.gwt.user.client.rpc.IsSerializable;

import javax.persistence.*;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;


/**
 * The persistent class for the comment database table.
 * 
 */
@Entity
public class Comment implements IsSerializable {
	private static final long serialVersionUID = 1L;
	
	@Column(columnDefinition = "text")
	private String comment;

	private Timestamp date;
	@Id
	@Column(columnDefinition = "text")
	private String id;

	@OneToOne
	@JoinColumn(name = "\"user\"",columnDefinition = "text default 'portal::ac6219edefc92a45b233f83e975102ec'")
	private User user;
	
	@OneToOne
	@JoinColumn(name = "template")
	private CommentTemplate template;

	/*@ManyToMany(fetch = FetchType.LAZY, mappedBy = "comments")
	private List<Budget> budgets = new ArrayList<>();*/

	@ManyToMany(fetch = FetchType.LAZY, mappedBy = "requestComments")
	@JsonBackReference
	private List<Request> requests = new ArrayList<>();
	
	public Comment() {
	}

	public Comment(User user, Timestamp date, String comment, CommentTemplate commentTemplate){
		this.user = user;
		this.date = date;
		this.comment = comment;
		this.template = commentTemplate;
	}

	public String getComment() {
		return this.comment;
	}

	public void setComment(String comment) {
		this.comment = comment;
	}

	public Timestamp getDate() {
		return this.date;
	}

	public void setDate(Timestamp date) {
		this.date = date;
	}

	public String getId() {
		return this.id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public User getUser() {
		return this.user;
	}

	public void setPerson(User user) {
		this.user = user;
	}

	public CommentTemplate getTemplate() {
		return this.template;
	}

	public void setTemplate(CommentTemplate template) {
		this.template = template;
	}

}