package com.nokia.common.http;

import lombok.Data;

/**
 * 返回值的统一包装
 */
@Data
public class R {
    private Boolean success;
    private Integer code;
    private String message;

    private Object data = null;

    /**
     * 私有化构造方法,不允许在外部实例化
     */
    private R() {
    }

    /**
     * 成功的静态方法
     *
     * @return R实例
     */
    public static R ok() {
        R r = new R();
        r.setSuccess(true);
        r.setCode(200);
        r.setMessage("成功");
        return r;
    }

    /**
     * 失败的静态方法
     *
     * @return R实例
     */
    public static R error() {
        R r = new R();
        r.setSuccess(false);
        r.setCode(500);
        r.setMessage("失败");
        return r;
    }
    public R success(Boolean success) {
        this.setSuccess(success);
        return this;
    }


    public R code(Integer code) {
        this.setCode(code);
        return this;
    }

    public R data(Object object) {
        this.setData(object);
        return this;
    }

    public R message(String message) {
        this.setMessage(message);
        return this;
    }
}
