using NetCord.Gateway;
using NetCord.Hosting.Gateway;

namespace GmRelay.DiscordBot.Infrastructure.Logging;

public sealed class DiscordGatewayLifecycleLogger(
    ILogger<DiscordGatewayLifecycleLogger> logger)
    : IConnectGatewayHandler,
      IReadyGatewayHandler,
      IDisconnectGatewayHandler,
      IResumeGatewayHandler
{
    public ValueTask HandleAsync()
    {
        logger.LogInformation("Discord gateway connected");
        return ValueTask.CompletedTask;
    }

    public ValueTask HandleAsync(ReadyEventArgs arg)
    {
        logger.LogInformation(
            "Discord gateway ready for application {ApplicationId} in {GuildCount} guilds",
            arg.ApplicationId,
            arg.GuildIds.Count);

        return ValueTask.CompletedTask;
    }

    public ValueTask HandleAsync(DisconnectEventArgs arg)
    {
        logger.LogWarning(
            "Discord gateway disconnected; reconnect scheduled: {Reconnect}",
            arg.Reconnect);

        return ValueTask.CompletedTask;
    }

    ValueTask IResumeGatewayHandler.HandleAsync()
    {
        logger.LogInformation("Discord gateway session resumed");
        return ValueTask.CompletedTask;
    }
}
