package com.goafanti.common.bo;

import org.apache.shiro.SecurityUtils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @param <T> 在Controller里面设置返回对象就可以用apipost读取到
 */
public class Result<T> {
	private T data;
	private List<Error>	error	= new ArrayList<Error>();
	private String token;
	public Result() {
		this.token = (String) SecurityUtils.getSubject().getSession().getId();
	}

	public Result(T data) {
		this.data = data;
	}

	/**
	 * @return the data
	 */
	public T getData() {
		return data;
	}

	/**
	 * @param data
	 *            the data to set
	 */
	public void setData(T data) {
		this.data = data;
	}

	/**
	 * @return the error
	 */
	public List<Error> getError() {
		return error;
	}

	/**
	 * @param error
	 *            the error to set
	 */
	public void setError(List<Error> error) {
		this.error = error;
	}

	public Result error(Error e) {
		if (e != null) {
			this.error.add(e);
		}
		return this;
	}

	public Result data(T o) {
		this.data = o;
		return this;
	}

	public Serializable getToken() {
		return token;
	}

	public void setToken(String  token) {
		this.token = token;
	}
}
