// Path: src/main/java/ninja/eivind/hotsreplayuploader/preloader/notifications/BeanLoadedNotification.java
// public class BeanLoadedNotification implements BeanNotification {
//     private final String beanName;
//     private final double progress;
// 
//     public BeanLoadedNotification(String beanName, double progress) {
//         this.beanName = beanName;
//         this.progress = progress;
//     }
// 
//     @Override
//     public String getBeanName() {
//         return beanName;
//     }
// 
//     public double getProgress() {
//         return progress;
//     }
// }
// 
// Path: src/main/java/ninja/eivind/hotsreplayuploader/preloader/notifications/BeanLoadingNotification.java
// public class BeanLoadingNotification implements BeanNotification {
//     private final String beanName;
// 
//     public BeanLoadingNotification(String beanName) {
//         this.beanName = beanName;
//     }
// 
//     @Override
//     public String getBeanName() {
//         return beanName;
//     }
// }


import javafx.application.Preloader;
import javafx.scene.control.ProgressIndicator;
import ninja.eivind.hotsreplayuploader.preloader.notifications.BeanLoadedNotification;
import ninja.eivind.hotsreplayuploader.preloader.notifications.BeanLoadingNotification;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        final int beanDefinitionCount = beanFactory.getBeanDefinitionCount();
        if (beanDefinitionCount >= minBeanDefCount) {
            this.beanDefinitionCount = beanDefinitionCount;
            notifyContextIsLoadingBean(beanName);
        }
        return bean;
    }

    private void notifyContextIsLoadingBean(String beanName) {
        handle.notifyPreloader(new BeanLoadingNotification(beanName));
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        loadedBeans++;
        final double progress;
        if (beanDefinitionCount > 0) {
            progress = (double) loadedBeans / (double) beanDefinitionCount;
            handle.notifyPreloader(new Preloader.ProgressNotification(progress));
        } else {
            progress = ProgressIndicator.INDETERMINATE_PROGRESS;
        }
        notifyContextLoadedBean(beanName, progress);
        return bean;
    }

    private void notifyContextLoadedBean(String beanName, double progress) {
// Path: src/main/java/ninja/eivind/hotsreplayuploader/preloader/notifications/BeanLoadedNotification.java
// public class BeanLoadedNotification implements BeanNotification {
//     private final String beanName;
//     private final double progress;
// 
//     public BeanLoadedNotification(String beanName, double progress) {
//         this.beanName = beanName;
//         this.progress = progress;
//     }
// 
//     @Override
//     public String getBeanName() {
//         return beanName;
//     }
// 
//     public double getProgress() {
//         return progress;
//     }
// }
// 
// Path: src/main/java/ninja/eivind/hotsreplayuploader/preloader/notifications/BeanLoadingNotification.java
// public class BeanLoadingNotification implements BeanNotification {
//     private final String beanName;
// 
//     public BeanLoadingNotification(String beanName) {
//         this.beanName = beanName;
//     }
// 
//     @Override
//     public String getBeanName() {
//         return beanName;
//     }
// }


// Path: src/main/java/ninja/eivind/hotsreplayuploader/preloader/ProgressMonitorBeanPostProcessor.java
import javafx.application.Preloader;
import javafx.scene.control.ProgressIndicator;
import ninja.eivind.hotsreplayuploader.preloader.notifications.BeanLoadedNotification;
import ninja.eivind.hotsreplayuploader.preloader.notifications.BeanLoadingNotification;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;


    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        final int beanDefinitionCount = beanFactory.getBeanDefinitionCount();
        if (beanDefinitionCount >= minBeanDefCount) {
            this.beanDefinitionCount = beanDefinitionCount;
            notifyContextIsLoadingBean(beanName);
        }
        return bean;
    }

    private void notifyContextIsLoadingBean(String beanName) {
        handle.notifyPreloader(new BeanLoadingNotification(beanName));
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        loadedBeans++;
        final double progress;
        if (beanDefinitionCount > 0) {
            progress = (double) loadedBeans / (double) beanDefinitionCount;
            handle.notifyPreloader(new Preloader.ProgressNotification(progress));
        } else {
            progress = ProgressIndicator.INDETERMINATE_PROGRESS;
        }
        notifyContextLoadedBean(beanName, progress);
        return bean;
    }

    private void notifyContextLoadedBean(String beanName, double progress) {
        handle.notifyPreloader(new BeanLoadedNotification(beanName, progress));