package com.uas.account.entity;

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

import com.uas.account.core.util.StringUtil;

public class Token implements Serializable {

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

	private String id;

	private Object bind;

	private Date time;

	private int expires_in;

	private String tel;

	private String email;

	/**
	 * 60秒过期
	 */
	public final static int default_expires_in = 60;

	public Token() {
	}

	public Token(Object bindObject) {
		this(bindObject, default_expires_in);
	}

	public Token(Object bindObject, int expires_in) {
		this(StringUtil.uuid(), bindObject, expires_in);
	}

	public Token(String id, Object bindObject, int expires_in) {
		this.id = id;
		this.bind = bindObject;
		this.time = new Date();
		this.expires_in = expires_in;
	}

	public Date getTime() {
		return time;
	}

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

	public int getExpires_in() {
		return expires_in;
	}

	public void setExpires_in(int expires_in) {
		this.expires_in = expires_in;
	}

	public String getId() {
		return id;
	}

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

	public Object getBind() {
		return bind;
	}

	public void setBind(Object bind) {
		this.bind = bind;
	}

	/**
	 * 是否过期
	 * 
	 * @return
	 */
	public boolean isExpired() {
		return System.currentTimeMillis() - this.time.getTime() > expires_in * 1000;
	}

	/**
	 * 验证码绑定的手机号
	 *
	 * @return
	 */
	public String getTel() {
		return tel;
	}

	public void setTel(String tel) {
		this.tel = tel;
	}

	public String getEmail() {
		return email;
	}

	/**
	 * 验证码绑定的邮箱
	 *
	 * @return
	 */
	public void setEmail(String email) {
		this.email = email;
	}
}
