package com.tiedup.remake.events.system;

import com.tiedup.remake.core.TiedUpMod;
import com.tiedup.remake.minigame.LockpickSessionManager;
import com.tiedup.remake.minigame.StruggleSessionManager;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

/**
 * Server tick handler for mini-game session management.
 *
 * Handles:
 * - Continuous struggle session ticking (direction changes, resistance updates, shock checks)
 * - Session cleanup for expired/disconnected sessions
 */
@Mod.EventBusSubscriber(
    modid = TiedUpMod.MOD_ID,
    bus = Mod.EventBusSubscriber.Bus.FORGE
)
public class MiniGameTickHandler {

    /**
     * Tick continuous struggle sessions every server tick.
     */
    @SubscribeEvent
    public static void onServerTick(TickEvent.ServerTickEvent event) {
        if (event.phase != TickEvent.Phase.END) return;

        long currentTick = event.getServer().getTickCount();

        // Tick continuous struggle sessions every tick
        StruggleSessionManager.getInstance().tickContinuousSessions(
            event.getServer(),
            currentTick
        );

        // Cleanup expired sessions periodically
        StruggleSessionManager.getInstance().tickCleanup(currentTick);
        LockpickSessionManager.getInstance().tickCleanup(currentTick);
    }
}
