package org.adrianvictor.lib;

import org.adrianvictor.lib.versioning.DefaultVersionedServiceFactory;
import org.adrianvictor.lib.versioning.VersionMatcher;
import org.adrianvictor.lib.versioning.VersionedServiceFactory;
import org.adrianvictor.lib.versioning.VersionedServiceRegistrar;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.ServiceLoader;

public class Main extends JavaPlugin {

    private static VersionedServiceFactory versionedServiceFactory;
    private static VersionMatcher versionMatcher;

    @Override
    public void onEnable() {
        versionMatcher = new VersionMatcher();

        versionedServiceFactory = new DefaultVersionedServiceFactory(versionMatcher);

        ServiceLoader<VersionedServiceRegistrar> registrars = ServiceLoader.load(VersionedServiceRegistrar.class);
        for (VersionedServiceRegistrar registrar : registrars) {
            registrar.register(versionedServiceFactory);
        }

        getLogger().info("tenkumaLib has been enabled!");
    }

    @Override
    public void onDisable() {
        getLogger().info("tenkumaLib has been disabled!");
    }

    public static VersionedServiceFactory getVersionedServiceFactory() {
        return versionedServiceFactory;
    }

    public static VersionMatcher getVersionMatcher() {
        return versionMatcher;
    }
}
