package com.ruoyi.common.utils;

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

public class ApiResult extends HashMap<String, Object> {
	private static final long serialVersionUID = 1L;

	public ApiResult() {
		put("code", 0);
		put("msg", "操作成功");
	}

	public static ApiResult error() {
		return error(1, "操作失败");
	}

	public static ApiResult error(String msg) {
		return error(500, msg);
	}

	public static ApiResult error(int code, String msg) {
		ApiResult apiResult = new ApiResult();
		apiResult.put("code", code);
		apiResult.put("msg", msg);
		return apiResult;
	}

	public static ApiResult ok(String msg) {
		ApiResult apiResult = new ApiResult();
		apiResult.put("msg", msg);
		return apiResult;
	}

	public static ApiResult ok(Map<String, Object> map) {
		ApiResult apiResult = new ApiResult();
		apiResult.putAll(map);
		return apiResult;
	}

	public static ApiResult ok() {
		return new ApiResult();
	}

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