package com.izouma.nineth.dto;

import com.izouma.nineth.config.Constants;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel("元宇宙通用返回类")
public class MetaRestResult<T> {

    @ApiModelProperty("返回消息")
    private String message;

    @ApiModelProperty("返回状态")
    private int code;

    @ApiModelProperty("返回数据")
    private T data;

    public static <T> MetaRestResult<T> returnSuccess(T data) {
        String successMsg = "请求成功";
        return returnSuccess(successMsg, data);
    }

    public static <T> MetaRestResult<T> returnSuccess(String successMessage, T data) {
        MetaRestResult<T> result = returnResult(data);
        result.setMessage(successMessage);
        result.setCode(Constants.MetaRestCode.success);
        return result;
    }

    public static <T> MetaRestResult<T> returnError(String errorMessage) {
        MetaRestResult<T> result = returnResult(null);
        result.setMessage(errorMessage);
        result.setCode(Constants.MetaRestCode.err);
        return result;
    }

    public static <T> MetaRestResult<T> returnError(String errorMessage, T date) {
        MetaRestResult<T> result = returnResult(date);
        result.setMessage(errorMessage);
        result.setCode(Constants.MetaRestCode.err);
        return result;
    }

    private static <T> MetaRestResult<T> returnResult(T data) {
        MetaRestResult<T> result = new MetaRestResult<>();
        result.setData(data);
        return result;
    }


}
