package org.minager.core.entities.persistence;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.Generated;
import org.hibernate.annotations.GenerationTime;
import org.minager.core.entities.security.Token;

@Entity
@Table(name="`user`")
public class User implements Serializable {
	private static final long serialVersionUID = 1L;

	/* ******************* */
	/* Attributes */
	/* ******************* */
	@Id
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator="user_id_seq")
	@SequenceGenerator(name="user_id_seq", sequenceName="user_id_seq", allocationSize=1)
	private Long id;
	
	// This annotation serves to fetch the attribute after an insert into db
	@Generated(GenerationTime.ALWAYS)
	private String key;
	
	private String name;
	
	private String email;
	
	private String password;
	
	private String image;
	
	@Column(name = "inscription_date")
	@Temporal(TemporalType.TIMESTAMP)
	private Date inscriptionDate;

	/** Authentication token. */
	private transient Token token;

	/* ******************* */
	/* Constructors */
	/* ******************* */
	public User() {
		super();
		token = new Token();
	}
	
	/* ******************* */
	/* Getters & Setters */
	/* ******************* */
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		if(this.id != null) {
			throw new IllegalAccessError("It's not allowed to rewrite the id entity.");
		}
		this.id = id;
	}

	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getImage() {
		return image;
	}

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

	public Date getInscriptionDate() {
		return inscriptionDate;
	}

	public void setInscriptionDate(Date inscriptionDate) {
		this.inscriptionDate = inscriptionDate;
	}

	public Token getToken() {
		return token;
	}
	
}
