package com.uas.platform.b2b.model;

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

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;

@Entity(name = "sec$token")
public class Token implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sec$token_gen")
	@SequenceGenerator(name = "sec$token_gen", sequenceName = "sec$token_seq", allocationSize = 1)
	private Long id;

	private String userType;

	private Long uu;

	private Date time;
	
	public Token() {
		this.time = new Date();
	}

	public Token(String type, Long uu) {
		this();
		this.userType = type.toLowerCase();
		this.uu = uu;
	}

	public Token(UserType type, Long uu) {
		this();
		this.userType = type.toString();
		this.uu = uu;
	}

	public Long getId() {
		return id;
	}

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

	public String getUserType() {
		return userType;
	}

	public void setUserType(String userType) {
		this.userType = userType;
	}

	public Long getUu() {
		return uu;
	}

	public void setUu(Long uu) {
		this.uu = uu;
	}

	public Date getTime() {
		return time;
	}

	public void setTime(Date time) {
		this.time = time;
	}

	/**
	 * 24小时超时
	 * 
	 * @return
	 */
	public boolean isOutofTime() {
		return System.currentTimeMillis() - this.time.getTime() > 86400000;
	}

	public enum UserType {
		enterprise, user;
	}
}
