package usda.weru.weps.wepsRunControl;

import java.awt.Component;
import javax.swing.JOptionPane;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; 

/**
 *
 * @author mhaas
 */
public class WrcException extends Exception {
    private static final long serialVersionUID = 1L;
    
    public enum wrcExceptionType {
        prismDataReadFail,
        stationNotFound,
        indexFileError,
        parFileError,
        other
    };
    
    private String message;
    private boolean isFatal = true;
    private wrcExceptionType type = wrcExceptionType.other;
    
    WrcException (String message) {
        this(message, null);
    }
    
    WrcException (String message, Throwable t) {
        super(message, t);
        this.message = message;
    }
    
    WrcException (String message, Logger Logger, String extraLogString) {
        this (message, null, Logger, extraLogString);
    }
    
    WrcException (String message, Throwable t, Logger Logger, String extraLogString) {
        this(message, t);
        
        if (Logger != null) {
            Logger.error(message + extraLogString);
        }
    }
    
    public WrcException setFatal (boolean isFatal) {
        this.isFatal = isFatal;
        return this;
    }
    
    public boolean getFatal () {
        return isFatal;
    }
    
    public WrcException setType (wrcExceptionType type) {
        this.type = type;
        return this;
    }
    
    public wrcExceptionType getType () {
        return type;
    }
    
    public WrcException addLog (Logger Logger, String extraLogString) {
        Logger.error(message + extraLogString);
        return this;
    }
    
    public WrcException addDlg (Component parent) {
        return addDlg(parent, "");
    }
    
    public WrcException addDlg (Component parent, String extraDlgString) {
        JOptionPane.showMessageDialog(parent, message + extraDlgString, "Error", JOptionPane.ERROR_MESSAGE);
        LogManager.getLogger(this.getClass()).error(message + extraDlgString);
        return this;
    }
}
