package com.chaozhanggui.common.system.config;

import com.alibaba.fastjson.JSONObject;

/**
 * 响应结果生成工具
 */
public class ResultGenerator {
    public static final String DEFAULT_SUCCESS_MESSAGE = "操作成功";
    public static final String DEFAULT_FAIL_MESSAGE = "操作失败！";

    public static <T> Result<T> genSuccessResult() {
        return new Result()
                .setCode(ResultCode.SUCCESS)
                .setMessage(DEFAULT_SUCCESS_MESSAGE);
    }
    
    public static Result genUndefinedResult(String message) {
    	return new Result()
    			.setCode(ResultCode.UNDEFINDE)
    			.setMessage(message);
    }

    public static <T> Result<T> genSuccessResult(String msg, T data) {
        return new Result<>(ResultCode.SUCCESS, msg, data);
    }

    public static <T> Result<T> genSuccessResult(T data) {
        return new Result<>(ResultCode.SUCCESS, DEFAULT_SUCCESS_MESSAGE, data);
    }

    public static <T> Result<T> genResult(String data) {
    	return new Result<>(ResultCode.SUCCESS, data);
    }
    
    public static Result genTransunKonwResult(String message) {
        return new Result<>().setCode(ResultCode.TRANSUNKNOW).setMessage(message);
    }
    
    public static <T> Result<T> genTransunKonwResult(String message,T data){
    	 return new Result<>(ResultCode.TRANSUNKNOW, message, data);
    }

    public static <T> Result<T> genFailResult(String message) {
        return new Result<>(ResultCode.FAIL, message, null);
    }
    
    public static <T> Result<T> genFailResult(String message,T data) {
        return new Result<>(ResultCode.FAIL, message, data);
    }
    
    
    public static <T> Result<T> genFailResult(T data) {
        return new Result<>(ResultCode.FAIL, DEFAULT_FAIL_MESSAGE, data);
    }

    public static JSONObject genFailJsonResult(String message) {
        JSONObject result = new JSONObject();
        result.put("code",ResultCode.FAIL.code());
        result.put("message",message);
        result.put("data",null);
        return result;
    }

    public static JSONObject genSuccessJsonResult(String message,Object data) {
        JSONObject result = new JSONObject();
        result.put("code",ResultCode.SUCCESS.code());
        result.put("message",message);
        result.put("data",data);
        return result;
    }
    public static JSONObject genSuccessJsonResult(Object data) {
        JSONObject result = new JSONObject();
        result.put("code",ResultCode.SUCCESS.code());
        result.put("message","请求成功");
        result.put("data",data);
        return result;
    }
    public static JSONObject genSuccessJsonPos(Object data, String appId, String requestId) {
        JSONObject result = new JSONObject();
        result.put("code","0000");
        result.put("msg","操作成功");
        result.put("appId", appId);
        result.put("requestId", requestId);
        result.put("respData", data);
        return result;
    }
    public static JSONObject genFailJsonPos(String msg, String appId, String requestId) {
        JSONObject result = new JSONObject();
        result.put("code","400");
        result.put("msg", msg);
        result.put("appId", appId);
        result.put("requestId", requestId);
        return result;
    }

}
