package com.nokia.tsl_data.entity.vo;

import lombok.Data;

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

    /**
     * 私有化构造方法,不允许在外部实例化
     */
    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 code(int code) {
        this.setCode(code);
        return this;
    }

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

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