package com.yfd.platform.config;

import java.util.HashMap;

public class ResponseResult extends HashMap<String, Object> {

    private static final long serialVersionUID = 1L;

    // 未登录状态码
    public static final String CODE_NOT_LOGIN = "401";
    // 成功状态码
    public static final String CODE_SUCCESS = "0";
    // 错误状态码
    public static final String CODE_ERROR = "1";

    public ResponseResult() {
    }

    public static ResponseResult unlogin() {
        return message(CODE_NOT_LOGIN, "未登录");
    }

    public static ResponseResult error() {
        return error("操作失败");
    }

    public static ResponseResult success() {
        return success("操作成功");
    }

    public static ResponseResult error(String msg) {
        ResponseResult json = new ResponseResult();
        json.put("code", CODE_ERROR);
        json.put("msg", msg);
        return json;
    }

    public static ResponseResult message(String code, String msg) {
        ResponseResult json = new ResponseResult();
        json.put("code", code);
        json.put("msg", msg);
        return json;
    }

    public static ResponseResult success(String msg) {
        ResponseResult json = new ResponseResult();
        json.put("code", CODE_SUCCESS);
        json.put("msg", msg);
        return json;
    }

    public static ResponseResult successData(Object obj) {
        ResponseResult json = new ResponseResult();
        json.put("code", CODE_SUCCESS);
        json.put("msg", "操作成功");
        json.put("data", obj);
        return json;
    }


    public ResponseResult put(String key, Object value) {
        super.put(key, value);
        return this;
    }
}
