package com.wisewoods.base.bean;

import com.google.gson.annotations.SerializedName;

public class Results<T> {

    /**
     * 结果码
     */
    @SerializedName(value = "code", alternate = "status")
    public int code;
    /**
     * 服务器端返回的结果码说明，可以用于toast显示
     */
    @SerializedName(value = "msg", alternate = "message")
    public String msg = "";
    /**
     * 具体的数据,可以是对象或者list
     */
    @SerializedName(value = "data", alternate = "result")
    public T data;

    private static final int SUCCESS = 200;
    private static final int FAIL = 500;

    //    @Expose
    public boolean isSuccess() {
        return code == SUCCESS;
    }

    public Results() {
    }

    public Results(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> Results<T> getSuccess(T data) {
        return new Results<>(SUCCESS, "", data);
    }

    public static <T> Results<T> getSuccess(String msg, T data) {
        return new Results<>(SUCCESS, msg, data);
    }

    public static <T> Results<T> getSuccess(String msg) {
        return getSuccess(msg, null);
    }

    public static <T> Results<T> getFail(int code, String msg) {
        return new Results<>(code, msg, null);
    }

    public static <T> Results<T> getFail(String msg) {
        return new Results<>(FAIL, msg, null);
    }

    public static <T> Results<T> getInitFail() {
        return new Results<>(FAIL, "数据未加载", null);
    }
}
