package com.livingworld;

import net.neoforged.fml.common.Mod;
import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.neoforge.common.NeoForge;
import net.neoforged.neoforge.event.server.ServerStartedEvent;
import net.neoforged.neoforge.event.server.ServerStartingEvent;
import net.neoforged.neoforge.event.server.ServerStoppingEvent;

import com.livingworld.bootstrap.LivingWorldBootstrap;
import com.livingworld.core.LivingWorldConstants;
import com.livingworld.debug.DiagnosticCategory;
import com.livingworld.debug.LivingWorldLogger;

/**
 * Mod entrypoint for Living World.
 * <p>
 * This class contains only mod loader wiring. All simulation logic is
 * delegated to the bootstrap system and core services.
 */
@Mod(LivingWorldConstants.MOD_ID)
public class LivingWorldMod {

    public static final String MOD_ID = LivingWorldConstants.MOD_ID;
    private final LivingWorldBootstrap bootstrap;

    public LivingWorldMod(IEventBus eventBus) {
        LivingWorldLogger.info(DiagnosticCategory.BOOTSTRAP, "Living World mod starting...");

        this.bootstrap = new LivingWorldBootstrap();
        this.bootstrap.initialize();

        eventBus.addListener(FMLCommonSetupEvent.class, event -> bootstrap.onCommonSetup());
        NeoForge.EVENT_BUS.addListener(
                ServerStartingEvent.class, event -> bootstrap.onServerStarting());
        NeoForge.EVENT_BUS.addListener(
                ServerStartedEvent.class, event -> bootstrap.onServerStarted());
        NeoForge.EVENT_BUS.addListener(
                ServerStoppingEvent.class, event -> bootstrap.onServerStopping());

        LivingWorldLogger.info(DiagnosticCategory.BOOTSTRAP, "Living World Bootstrap initialized successfully.");
    }
}
