package com.persagy.calendar.utils;

import com.alibaba.fastjson.JSONObject;

/**
 * @version 
 * @description 
 * @company persagy
 * @author zhangqiankun
 * @since 2020年9月1日:	下午2:21:25
 */
public class ResponseOldResultUtil {
	
	public static final String RESULT_SUCCESS = "success";
	
	public static final String RESULT_FAILURE = "failure";
	
	public static final String RESULT_EMPTY = "";
	
	public static ResponseOldResult successResult() {
		ResponseOldResult result = new ResponseOldResult();
		result.setResult(RESULT_SUCCESS);
		result.setRespMsg(RESULT_EMPTY);
		return result;
	}
	
	/**
	 * 此项目不建议再直接返回json数据，多一步转换，若为json数据，建议controller层直接返回string类型
	 * @param jsonData Content数据，必须为json格式数据
	 */
	public static ResponseOldResult successResultContent(String jsonData) {
		ResponseOldResult result = new ResponseOldResult();
		result.setResult(RESULT_SUCCESS);
		// 此处不转换，实际数据会被加上反斜杠
		result.setContent(JSONObject.parseObject(jsonData));
		return result;
	}
	
	/**
	 * @param data	Content数据，不允许为json格式数据，可以是普通string字符串
	 */
	public static ResponseOldResult successResultContent(Object data) {
		ResponseOldResult result = new ResponseOldResult();
		result.setResult(RESULT_SUCCESS);
		result.setContent(data);
		return result;
	}
	
	public static ResponseOldResult successResultId(String id) {
		ResponseOldResult result = new ResponseOldResult();
		result.setResult(RESULT_SUCCESS);
		result.setRespMsg(RESULT_EMPTY);
		result.setId(id);
		return result;
	}
	
	public static ResponseOldResult successResultContent(Object data, Integer totalCount) {
		ResponseOldResult result = new ResponseOldResult();
		result.setResult(RESULT_SUCCESS);
		result.setContent(data);
		result.setCount(totalCount);
		return result;
	}

	public static ResponseOldResult errorResultMsg(String respMsg) {
		ResponseOldResult result = new ResponseOldResult();
		result.setResult(RESULT_FAILURE);
		result.setRespMsg(respMsg);
		return result;
	}

	/**
	 * 此项目不建议再直接返回json数据，多一步转换，若为json数据，建议controller层直接返回string类型
	 * @param jsonData Content数据，必须为json格式数据
	 */
	public static ResponseOldResult errorResultMsg(String respCode, String respMsg, String jsonData) {
		ResponseOldResult result = new ResponseOldResult();
		result.setResult(RESULT_FAILURE);
		result.setRespMsg(respMsg);
		// 此处不转换，实际数据会被加上反斜杠
		result.setContent(JSONObject.parseObject(jsonData));
		return result;
	}
	
	/**
	 * @param respCode
	 * @param respMsg
	 * @param content Content数据，不允许为json格式数据，可以是普通string字符串
	 * @return
	 */
	public static ResponseOldResult errorResultMsg(String respCode, String respMsg, Object content) {
		ResponseOldResult result = new ResponseOldResult();
		result.setResult(RESULT_FAILURE);
		result.setRespMsg(respMsg);
		result.setContent(content);
		return result;
	}

}
