package com.ruoyi.common.third.exception;

import org.springframework.util.ObjectUtils;

public class EncryptException extends RuntimeException{
    private static final long serialVersionUID = -7369999214547220108L;
    /**
     * 异常code
     * */
    private Integer exceptionCode = 10001;
    /**
     * 异常提示信息
     * */
    private String message;
    /**
     * 如果flag==true，则抛出message异常
     * @param flag 标记
     * @param message 异常信息
     */
    public static void throwBy(boolean flag, String message) {
        if(flag) {
            throw new EncryptException(message);
        }
    }
    /**
     * 如果flag==true，则抛出message异常
     * @param flag 标记
     * @param message 异常信息
     * @param exceptionCode 异常code
     */
    public static void throwBy(boolean flag,Integer exceptionCode, String message) {
        if(flag) {
            throw new EncryptException(exceptionCode, message);
        }
    }

    /**
     * 如果value==null或者isEmpty，则抛出message异常
     * @param value 值
     * @param message 异常信息
     */
    public static void throwByNull(Object value, String message) {
        if(ObjectUtils.isEmpty(value)) {
            throw new EncryptException(message);
        }
    }
    /**
     * 如果value==null或者isEmpty，则抛出message异常
     * @param value 值
     * @param message 异常信息
     * @param exceptionCode 异常code
     */
    public static void throwByNull(Object value, Integer exceptionCode, String message) {
        if(ObjectUtils.isEmpty(value)) {
            throw new EncryptException(exceptionCode, message);
        }
    }

    public EncryptException() {
    }

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

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

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

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

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

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

    public Integer getExceptionCode() {
        return exceptionCode;
    }

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

    @Override
    public String getMessage() {
        return message;
    }

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