package xyz.tbvns.rogue_block.Upgrades;

import lombok.Getter;
import org.reflections.Reflections;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

public class UpgradesManager {
    public static final List<Upgrade> registeredUpgrades = new ArrayList<>();

    public static void loadUpgrades() {
        try {
            Reflections reflections = new Reflections("xyz.tbvns.rogue_block.Upgrades.RegisteredUpgrades");

            Set<Class<? extends PassiveUpgrade>> passiveUpgrade = reflections.getSubTypesOf(PassiveUpgrade.class);
            for (Class<? extends PassiveUpgrade> element : passiveUpgrade) {
                registeredUpgrades.add(element.getDeclaredConstructor().newInstance());
            }

            Set<Class<? extends ActiveUpgrade>> activeUpgrade = reflections.getSubTypesOf(ActiveUpgrade.class);
            for (Class<? extends ActiveUpgrade> element : activeUpgrade) {
                registeredUpgrades.add(element.getDeclaredConstructor().newInstance());
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public void registerUpgrade(Class<? extends Upgrade> upgrade) {
        try {
            registeredUpgrades.add(upgrade.getDeclaredConstructor().newInstance());
        } catch (Exception e) {
            throw new RuntimeException();
        }
    }
}
