package com.alttd.webinterface.bot;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.dv8tion.jda.api.events.session.ReadyEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import org.jetbrains.annotations.NotNull;

@Slf4j
@RequiredArgsConstructor
public class ReadyListener extends ListenerAdapter {

    private final Runnable onReadyCallback;

    @Override
    public void onReady(@NotNull ReadyEvent event) {
        log.info("JDA is ready. Guilds loaded: {}", event.getJDA().getGuilds().size());
        if (onReadyCallback != null) {
            try {
                onReadyCallback.run();
            } catch (Exception e) {
                log.error("Error running onReady callback", e);
            }
        }
    }
}
