package com.sqx.common.utils;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.apache.http.HttpStatus;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * 返回数据-泛型版
 *
 */
@ApiModel("统一返回值")
@Data
public class Result2<T> implements Serializable {
	private static final long serialVersionUID = 1L;

	@ApiModelProperty(value = "状态码,0为正常，500为异常", example = "0")
	private int code = 0;

	@ApiModelProperty(value = "消息", example = "保存成功！")
	private String msg;

	@ApiModelProperty(value = "返回对象")
	private T data;

	public Result2<T> error() {
		return error(HttpStatus.SC_INTERNAL_SERVER_ERROR, "未知异常，请联系管理员");
	}
	
	public Result2<T> error(String msg) {
		return error(HttpStatus.SC_INTERNAL_SERVER_ERROR, msg);
	}
	
	public Result2<T> error(int code, String msg) {
		this.code = code;
		this.msg = msg;
		return this;
	}

	public Result2<T> success(String msg) {
		this.msg = msg;
		return this;
	}
	
	public Result2<T> success() {
		return new Result2<>();
	}

}
