package org.shunt.common;

import java.io.Serializable;

import javax.validation.Valid;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
/** 
* @ClassName: XmoseResponse 
* @Description: API响应包装基类 
* @author caogang
* @date 2021年5月19日 上午9:55:57 
* 
* @param <T> 
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
@ApiModel("协议响应体")
public class XmoseResponse <T> implements Serializable {
	private static final long serialVersionUID = -692195163465409100L;


	public final static Integer CODE_SUCCESS = 200;// 成功时状态码
	public final static Integer CODE_TOKEN_EXPIRED = 201;// token超时
	public final static Integer CODE_TOKEN_EMPTY = 202;// token为空
	public final static Integer CODE_TOKEN_INVALID = 203;// token非法
	
	public final static Integer CODE_CONFIG = 402;// 业务数据配置缺失时错误码
	public final static Integer CODE_FORBIDDEN = 403;// 超出服务范围时，禁止提供服务（熔断，高并发限流）时，错误码
	public final static Integer CODE_INTERNEL = 500;// 未定义的系统异常（Exception）时，错误码
	public final static Integer CODE_UNAUTHORIZED = 401;// 业务未授权时进行访问，401（权限校验）
	public final static Integer CODE_UNSUPPORTED = 402;// 方法参数错误
	
	public final static String MSG = "ok";
	public final static String MSG_INVALID_TOKEN = "非法token";// 非法token
	public final static String MSG_INVALID_TOKEN_CODE = "非法token状态码";// 非法token状态码
	public final static String MSG_BUSI = "系统忙";// 系统忙


	
	@ApiModelProperty(value = "请求requestUid,时间戳")
	private String responseUid;
	
	@ApiModelProperty(value = "响应编码")
	private Integer code = CODE_SUCCESS;
	
	@ApiModelProperty(value = "响应信息")
	private String msg = MSG;
	
	@ApiModelProperty(value = "请求体")
	@Valid
	private T data;

	public XmoseResponse(Integer code, String msg, T data) {
		super();
		this.code = code;
		this.msg = msg;
		this.data = data;
	}

	public static <T> XmoseResponse<T> success() {
		return new XmoseResponse<T>(CODE_SUCCESS, MSG, null);
	}
	public static <T> XmoseResponse<T> success(T data) {
		return new XmoseResponse<T>(CODE_SUCCESS, MSG, data);
	}
	public static <T> XmoseResponse<T> fail(Integer code, String msg) {
		return new XmoseResponse<T>(code, msg, null);
	}
}
