package fastweb.config;

import java.util.HashMap;
import java.util.Map;

public class R {
    private boolean success;
    private String msg;
    private Map<String, Object> payloadMap;

    private R(boolean success, String msg, Map<String, Object> payloadMap) {
        this.success = success;
        this.msg = msg;
        this.payloadMap = payloadMap;
    }

    public static R ok(Map<String, Object> payloadMap) {
        return new R(true, "", payloadMap);
    }

    public static R error(String msg) {
        return new R(false, msg, new HashMap<>());
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Map<String, Object> getPayloadMap() {
        return payloadMap;
    }

    public void setPayloadMap(Map<String, Object> payloadMap) {
        this.payloadMap = payloadMap;
    }

    @Override
    public String toString() {
        return "R{" +
                "success=" + success +
                ", msg='" + msg + '\'' +
                ", payloadMap=" + payloadMap +
                '}';
    }
}
