package com.backendsys.modules.common.utils;

import org.apache.http.HttpStatus;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * 返回数据
 */
public class Result extends LinkedHashMap<String, Object> {
	private static final long serialVersionUID = 1L;
	
	public Result() {
		put("code", 200);
		put("message", "success");
	}
	
	public static Result error() {
		return error(HttpStatus.SC_INTERNAL_SERVER_ERROR, "系统异常");
	}
	
	public static Result error(String msg) {
		return error(HttpStatus.SC_INTERNAL_SERVER_ERROR, msg);
	}
	
	public static Result error(int code, String msg) {
		Result r = new Result();
		r.put("code", code);
		r.put("message", msg);
		return r;
	}

	public static Result error(int code, String msg, Object obj) {
		Result r = new Result();
		r.put("code", code);
		r.put("message", msg);
		r.put("data", obj);
		return r;
	}

	public static Result success(String msg) {
		Result r = new Result();
		r.put("message", msg);
		return r;
	}
	
	public static Result success(Map<String, Object> map) {
		Result r = new Result();
		r.putAll(map);
		return r;
	}
	
	public static Result success() {
		return new Result();
	}

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