package cn.meowrain.aioj.backend.framework.core.web;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serial;
import java.io.Serializable;

/**
 * 全局返回对象
 */
@Data
@Accessors(chain = true)
public class Result<T> implements Serializable {

	@Serial
	private static final long serialVersionUID = 1L;

	/**
	 * 正确返回码
	 */
	public static final String SUCCESS_CODE = "0";

	/**
	 * 响应码
	 */
	private String code;

	/**
	 * 响应数据
	 */
	private T data;

	/**
	 * 响应信息
	 */
	private String message;

	/**
	 * 返回是否是正确响应
	 * @return boolean
	 */
	@JsonIgnore
	public boolean isSuccess() {
		return SUCCESS_CODE.equals(code);
	}

	/**
	 * 返回是否是错误响应
	 * @return boolean
	 */
	@JsonIgnore
	public boolean isFail() {
		return !isSuccess();
	}

}
