package com.jsowell.common.response;

import com.jsowell.common.enums.ykc.ReturnCodeEnum;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

@Data
public class RestApiResponse<T> {
	/**
	 * 返回码
	 */
	private String resCode;

	/**
	 * 信息
	 */
	private String msg;

	/**
	 * 数据
	 */
	private T obj;

	public RestApiResponse() {
		this.resCode = ReturnCodeEnum.CODE_SUCCESS.getValue();
		this.msg = ReturnCodeEnum.CODE_SUCCESS.getLabel();
	}

	public RestApiResponse(T t) {
		this.resCode = ReturnCodeEnum.CODE_SUCCESS.getValue();
		this.msg = ReturnCodeEnum.CODE_SUCCESS.getLabel();
		this.obj = t;
	}

	public RestApiResponse(String resCode, String msg) {
		this.resCode = resCode;
		this.msg = msg;
	}

	public RestApiResponse(ReturnCodeEnum returnCodeEnum) {
		this.resCode = returnCodeEnum.getValue();
		this.msg = returnCodeEnum.getLabel();
	}

	@Override
	public String toString() {
		return new ToStringBuilder(this, ToStringStyle.JSON_STYLE)
				.append("resCode", resCode)
				.append("msg", msg)
				.append("obj", obj)
				.toString();
	}
}
