package com.nokia.common.http;

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

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

    private Map<String, Object> data = new HashMap<>();

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

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

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

    public R success(Boolean success) {
        this.setSuccess(success);
        return this;
    }

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

    public R data(String key, Object value) {
        this.data.put(key, value);
        return this;
    }

    public R data(Map<String, Object> map) {
        this.setData(map);
        return this;
    }

    public Boolean getSuccess() {
        return success;
    }

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

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Map<String, Object> getData() {
        return data;
    }

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