package ru.kirillius.pf.sdn.core.Subscription;

import ru.kirillius.pf.sdn.core.Context;
import ru.kirillius.pf.sdn.core.Networking.NetworkResourceBundle;

import java.lang.reflect.InvocationTargetException;
import java.util.Map;

/**
 * Loads network resource bundles from a repository described by {@link RepositoryConfig}.
 */
public interface SubscriptionProvider {
    Map<String, NetworkResourceBundle> getResources(RepositoryConfig config);

    static SubscriptionProvider instantiate(Class<? extends SubscriptionProvider> providerClass, Context context) {
        try {
            var constructor = providerClass.getConstructor(Context.class);
            return constructor.newInstance(context);
        } catch (NoSuchMethodException | InvocationTargetException | InstantiationException |
                 IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    }
}
