package dev.micle.loginprotection;

import dev.micle.loginprotection.proxy.IProxy;
import dev.micle.loginprotection.proxy.Proxy;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.ModContainer;
import net.minecraftforge.fml.ModList;
import net.minecraftforge.fml.common.Mod;

import java.util.Optional;

@Mod(LoginProtection.MOD_ID)
public class LoginProtection {
    public static final String MOD_ID = "loginprotection";
    private static IProxy proxy;

    public LoginProtection() {
        proxy = DistExecutor.safeRunForDist(
                () -> Proxy.Client::new,
                () -> Proxy.Server::new
        );
    }

    public static ResourceLocation createResourceLocation(String name) throws IllegalArgumentException {
        if (name.contains(":")) {
            throw new IllegalArgumentException("Name contains namespace!");
        }
        return new ResourceLocation(MOD_ID, name);
    }

    public static String getVersion() {
        Optional<? extends ModContainer> modContainer = ModList.get().getModContainerById(MOD_ID);
        if (modContainer.isPresent()) {
            return modContainer.get().getModInfo().getVersion().toString();
        }
        return "0.0.0";
    }

    public static IProxy getProxy() {
        return proxy;
    }
}
