package fi.csc.chipster.auth.model;

import java.time.Instant;

import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.Version;
import javax.xml.bind.annotation.XmlRootElement;

import com.fasterxml.jackson.annotation.JsonUnwrapped;

@Entity // db
@XmlRootElement // json
public class User {		
		
	@EmbeddedId // db
	@JsonUnwrapped // rest
	private UserId userId;

	private String mail;
	private String organization;
	private String name;
	
	@Version
	private long version;
	
	private Instant	created;
	private Instant	modified;
	private Instant	accessed;
	
	
	public User() {
		// JAX-B needs this
	}

	public User(String username, String mail, String organization, String name) {
		this(null, username, mail, organization, name);
	}
	
	public User(String auth, String username, String mail, String organization, String name) {
		this.userId = new UserId(auth, username);
		this.mail = mail;
		this.organization = organization;
		this.name = name;
	}

	public String getMail() {
		return mail;
	}


	public void setMail(String mail) {
		this.mail = mail;
	}


	public String getOrganization() {
		return organization;
	}


	public void setOrganization(String organization) {
		this.organization = organization;
	}


	public long getVersion() {
		return version;
	}


	public void setVersion(long version) {
		this.version = version;
	}

	public Instant getCreated() {
		return created;
	}


	public void setCreated(Instant created) {
		this.created = created;
	}


	public Instant getModified() {
		return modified;
	}


	public void setModified(Instant modified) {
		this.modified = modified;
	}


	public Instant getAccessed() {
		return accessed;
	}


	public void setAccessed(Instant accessed) {
		this.accessed = accessed;
	}

	public String getName() {
		return name;
	}


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

	public UserId getUserId() {
		return userId;
	}

	public void setUserId(UserId userId) {
		this.userId = userId;
	}
}

@@ -474,16 +474,94 @@
 name;%0A%09%0A
+%09// terms of use%0A%09private int termsVersion;%0A%09private Instant termsAccepted;%0A%09%0A
 %09@Versio
@@ -2067,11 +2067,321 @@
 erId;%0A%09%7D
+%0A%0A%09public int getTermsVersion() %7B%0A%09%09return termsVersion;%0A%09%7D%0A%0A%09public void setTermsVersion(int termsVersion) %7B%0A%09%09this.termsVersion = termsVersion;%0A%09%7D%0A%0A%09public Instant getTermsAccepted() %7B%0A%09%09return termsAccepted;%0A%09%7D%0A%0A%09public void setTermsAccepted(Instant termsAccepted) %7B%0A%09%09this.termsAccepted = termsAccepted;%0A%09%7D
 %0A%7D%0A

Store the approval of terms of use