package org.aohe.result;

import cn.hutool.json.JSONUtil;
import lombok.Data;

@Data
public class R<T> {
    
    private String code;
    
    private String msg;
    
    private T data;
    
    private boolean success;
    
    public R (String code, String msg, T data, boolean success) {
        this.code = code;
        this.msg = msg;
        this.data = data;
        this.success = success;
    }
    
    public static R ok(Object data) {
        return new R<>("200", "ok", data, true);
    }
    
    public static R ok() {
        return new R<>("200", "ok", null, true);
    }
    
    public static R fail(String msg) {
        return new R<>("500", msg, null, false);
    }
    
    public String toJsonStr() {
        return JSONUtil.toJsonStr(this);
    }
}
