package com.iamberry.wechat.tools;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * @company	深圳爱贝源科技有限公司
 * @website www.iamberry.com
 * @author 	献
 * @tel		18271840547
 * @date	2016年9月5日
 * @explain	返回数据的json格式封装
 */
public class ResponseJson implements Serializable {

	private static final long serialVersionUID = -3391219323921796355L;

	private int resultCode = 200;			// 请求code
	
	private String resultMsg = "SUCCESS";	// 请求code描述
	
	private Integer returnCode;				// 业务结果
	
	private Map<String, Object> message;	// 返回的结果信息

	/**
	 * 成功时返回
	 */
	public static ResponseJson SUCCESS = new ResponseJson(200, "SUCCESS", 200);

	/**
	 * 失败时返回
	 */
	public static ResponseJson FAILURE = new ResponseJson(200, "FAILURE", 500);


	public final static ResponseJson getSUCCESS(){
		return  new ResponseJson(200, "SUCCESS", 200);
	}

	public final static ResponseJson getFAILURE(){
		return  new ResponseJson(200, "FAILURE", 500);
	}

	public ResponseJson() {
		super();
	}

	public int getResultCode() {
		return resultCode;
	}

	public void setResultCode(int resultCode) {
		this.resultCode = resultCode;
	}

	public String getResultMsg() {
		return resultMsg;
	}

	public void setResultMsg(String resultMsg) {
		this.resultMsg = resultMsg;
	}

	public Integer getReturnCode() {
		return returnCode;
	}

	public void setReturnCode(Integer returnCode) {
		this.returnCode = returnCode;
	}

	public Map<String, Object> getReturnMsg() {
		return message;
	}

	public void setReturnMsg(Map<String, Object> returnMsg) {
		this.message = returnMsg;
	}
	
	/**
	 * 添加返回结果 returnMsg='value'结果
	 * @param key
	 * @param value
	 */
	public ResponseJson addResponseKeyValue(String value) {
		if (this.message == null) {
			message = new HashMap<String, Object>();
		}
		this.message.put("returnMsg", value);
		return this;
	}

	/**
	 * 添加返回结果 key='value'结果
	 * @param key
	 * @param value
	 */
	public ResponseJson addResponseKeyValue(String Key, Object value) {
		if (this.message == null) {
			message = new HashMap<String, Object>();
		}
		this.message.put(Key, value);
		return this;		
	}

	public ResponseJson(int resultCode, String resultMsg, Integer returnCode) {
		super();
		this.resultCode = resultCode;
		this.resultMsg = resultMsg;
		this.returnCode = returnCode;
	}

	public ResponseJson(Integer returnCode, String returnMsg){
		super();
		this.returnCode = returnCode;
		addResponseKeyValue(returnMsg);
	}
}
