package com.hdkj.hussar;

import org.springframework.util.ObjectUtils;

/**
 * @author rj
 * @date 2026/1/28 9:51
 * @description
 */
public class HussarException extends RuntimeException {
    private static final long serialVersionUID = -7369999214547220108L;
    private Integer exceptionCode = 10001;
    private String message;

    public static void throwBy(boolean flag, String message) {
        if (flag) {
            throw new HussarException(message);
        }
    }

    public static void throwBy(boolean flag, Integer exceptionCode, String message) {
        if (flag) {
            throw new HussarException(exceptionCode, message);
        }
    }

    public static void throwByNull(Object value, String message) {
        if (ObjectUtils.isEmpty(value)) {
            throw new HussarException(message);
        }
    }

    public static void throwByNull(Object value, Integer exceptionCode, String message) {
        if (ObjectUtils.isEmpty(value)) {
            throw new HussarException(exceptionCode, message);
        }
    }

    public HussarException() {
    }

    public HussarException(Integer exceptionCode, String message) {
        super(message);
        this.exceptionCode = exceptionCode;
        this.message = message;
    }

    public HussarException(Integer exceptionCode, String message, Throwable cause) {
        super(message, cause);
        this.exceptionCode = exceptionCode;
        this.message = message;
    }

    public HussarException(Integer exceptionCode) {
        super("操作失败");
        this.exceptionCode = exceptionCode;
        this.message = "操作失败";
    }

    public HussarException(String message) {
        super(message);
        this.message = message;
    }

    public HussarException(String message, Throwable cause) {
        super(message, cause);
        this.message = message;
    }

    public HussarException(Throwable cause) {
        super(cause);
    }

    public Integer getExceptionCode() {
        return this.exceptionCode;
    }

    public void setExceptionCode(Integer exceptionCode) {
        this.exceptionCode = exceptionCode;
    }

    public String getMessage() {
        return this.message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}
