package wtf.opal;

import dev.crucifixbeta.mod.auth.RLGGAntiReverse;
import dev.crucifixbeta.mod.auth.RLGGAuthManager;
import dev.crucifixbeta.mod.auth.RLGGAuthWindow;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.minecraft.client.MinecraftClient;
import wtf.opal.client.OpalClient;
import wtf.opal.client.window.WindowTitleScroller;

@Environment(EnvType.CLIENT)
public final class OpalFabric implements ClientModInitializer {
    private final WindowTitleScroller titleScroller = new WindowTitleScroller();

    @Override
    public void onInitializeClient() {
        // initializeAntiReverse();
        // RLGGAuthWindow.requireVerified();
        OpalClient.setInstance();
        ClientTickEvents.END_CLIENT_TICK.register(titleScroller::tick);
        // RLGGAuthManager.startHeartbeat(this::stopClientAfterAuthFailure);
    }

    private static void initializeAntiReverse() {
        try {
            Class.forName(RLGGAntiReverse.class.getName(), true, RLGGAntiReverse.class.getClassLoader());
        } catch (ClassNotFoundException exception) {
            throw new IllegalStateException("Unable to initialize the anti-reverse guard", exception);
        }
    }

    private void stopClientAfterAuthFailure() {
        MinecraftClient.getInstance().scheduleStop();
    }
}
