package com.engine.htsc.trip.util;

import java.io.Serializable;

/**
 * Created by qlk
 */
public class AjaxResult<T> implements Serializable {

    private static final long serialVersionUID = -4302377008637324176L;

    /**
     * 状态码
     */
    private long code;
    /**
     * 提示信息
     */
    private String message;
    /**
     * 数据封装
     */
    private T data;

    public long getCode() {
        return code;
    }

    public void setCode(long code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public AjaxResult() {
    }

    public AjaxResult(long code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    /**
     * 成功返回结果
     * @param data 获取的数据
     */
    public static <T> AjaxResult<T> ok(T data) {
        return new AjaxResult<T>(200, "", data);
    }

    /**
     * 成功返回结果
     * @param data 获取的数据
     * @param  message 提示信息
     */
    public static <T> AjaxResult<T> ok(T data, String message) {
        return new AjaxResult<T>(200, message, data);
    }

    /**
     * 失败返回结果
     */
    public static <T> AjaxResult<T> failed() {
        return new AjaxResult<T>(400, "fail", null);
    }

    /**
     * 失败返回结果
     */
    public static <T> AjaxResult<T> error() {
        return new AjaxResult<T>(500, "error", null);
    }

    /**
     * 失败返回结果
     * @param  message 提示信息
     */
    public static <T> AjaxResult<T> failed(String message) {
        return new AjaxResult<T>(400, message, null);
    }

    /**
     * 失败返回结果
     * @param message 异常
     */
    public static <T> AjaxResult<T> error(String message) {
        return new AjaxResult<T>(500, message, null);
    }

    @Override
    public String toString() {
        return "AjaxResult{" +
                "code=" + code +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }
}
