package thyyxxk.webserver.entity;

import lombok.Data;
import thyyxxk.webserver.config.exception.ExceptionEnum;
import thyyxxk.webserver.config.exception.ExceptionEnumInterface;

import java.util.Objects;

/**
 * @author dj
 */
@Data
public class ResultVo<T> {
    private Integer code;
    private String message;
    private T data;


    public ResultVo(Integer code, String message) {
        this.code = code;
        this.message = message;
        this.data = null;
    }

    public ResultVo() {
        this.code = ExceptionEnum.SUCCESS.getCode();
        this.message = ExceptionEnum.SUCCESS.getMessage();
    }

    public ResultVo(T data) {
        this.code = ExceptionEnum.SUCCESS.getCode();
        this.message = ExceptionEnum.SUCCESS.getMessage();
        this.data = data;
    }

    public boolean isSuccess() {
        return Objects.equals(this.code, ExceptionEnum.SUCCESS.getCode()); // 与成功状态码比较
    }

    public ResultVo(ExceptionEnumInterface exceptionEnum, String message, T data) {
        this.code = exceptionEnum.getCode();
        this.message = message;
        this.data = data;
    }

    public ResultVo(ExceptionEnumInterface exceptionEnum) {
        this.code = exceptionEnum.getCode();
        this.message = exceptionEnum.getMessage();
    }

    public ResultVo(ExceptionEnumInterface exceptionEnum, String message) {
        this.code = exceptionEnum.getCode();
        this.message = message;
    }

    public ResultVo(ExceptionEnumInterface exceptionEnum, T data) {
        this.code = exceptionEnum.getCode();
        this.message = exceptionEnum.getMessage();
        this.data = data;
    }
}
