package common.utils.http;

import com.jfinal.kit.Ret;

public class MyRet extends Ret {
    public static final int CODE_OK = 0;                // 正常
    public static final int CODE_NO_LOGIN = 1;          // 未登录
    public static final int CODE_NO_POWER = 2;          // 没有权限
    public static final int CODE_FAILED = 3;            // 一般错误
    public static final int CODE_NO_AUTH = 4;           // 未实名认证
    public static final int CODE_NO_ADDR = 5;           // 未设置默认地址

    public static MyRet fail(String msg) {
        return new MyRet().setState(false).setCode(CODE_FAILED).setMsg(msg);
    }

    public static MyRet ok(String msg) {
        return new MyRet().setState(true).setCode(CODE_OK).setMsg(msg);
    }

    public MyRet setState(boolean state) {
        this.set("state", state);

        return this;
    }

    public boolean isOk() {
        return this.getBoolean("state");
    }

    public MyRet setCode(int code) {
        this.set("code", code);

        return this;
    }

    public MyRet setMsg(String msg) {
        this.set("msg", msg);

        return this;
    }

    public MyRet setData(Object obj) {
        this.set("data", obj);
        return this;
    }
}
