package org.jabref.logic;

import org.jspecify.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class JabRefException extends Exception {

    private static final Logger LOGGER = LoggerFactory.getLogger(JabRefException.class);
    @Nullable private String localizedMessage;

    public JabRefException(String message) {
        super(message);
    }

    public JabRefException(String message, Throwable cause) {
        super(message, cause);
    }

    public JabRefException(String message, @Nullable String localizedMessage) {
        super(message);
        this.localizedMessage = localizedMessage;
    }

    public JabRefException(String message, @Nullable String localizedMessage, Throwable cause) {
        super(message, cause);
        this.localizedMessage = localizedMessage;
    }

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

    @Override
    public String getLocalizedMessage() {
        if (localizedMessage == null) {
            String message = getMessage();
            LOGGER.debug("No localized exception message defined. Falling back to getMessage() ({}).", message);
            return message;
        } else {
            return localizedMessage;
        }
    }
}
