package com.ruoyi.web.controller.tool.testTool;

import com.ruoyi.web.controller.tool.testTool.ResultEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.*;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class ResultVo<T> implements Serializable {
//    @Serial
    private static final long serialVersionUID = 1L;
    private Integer code;
    private String msg;
    private T data;

    public static <T> ResultVo<T> ok(T data) {
        ResultEnum success = ResultEnum.SUCCESS;
        return new ResultVo<>(success.getCode(), success.getMessage(), data);
    }

    public static <T> ResultVo<T> ok() {
        ResultEnum success = ResultEnum.SUCCESS;
        return new ResultVo<>(success.getCode(), success.getMessage(), null);
    }

    public static <T> ResultVo<T> error() {
        ResultEnum success = ResultEnum.UNKNOWN_ERROR;
        return new ResultVo<>(success.getCode(), success.getMessage(), null);
    }

    public static <T> ResultVo<T> error(ResultEnum resultEnum) {
        return new ResultVo<>(resultEnum.getCode(), resultEnum.getMessage(), null);
    }

    public static <T> ResultVo<T> error(String msg) {
        ResultEnum customizeError = ResultEnum.CUSTOMIZE_ERROR;
        return new ResultVo<>(customizeError.getCode(), msg, null);
    }
    public static <T> ResultVo<T> error(Integer code,String msg) {
        return new ResultVo<>(code, msg, null);
    }
    public static <T> ResultVo<T> error(Integer code,String msg, T data) {
        return new ResultVo<>(code, msg, data);
    }

}
