using AyCode.Core.Loggers;
using AyCode.Services.SignalRs;
using Microsoft.AspNetCore.SignalR.Client;
using Microsoft.Extensions.Logging;

namespace FruitBankHybrid.Shared.Services.SignalRs;

/// <summary>
/// FruitBank-specific hub-connection setup.
/// <para>
/// Connection-level configuration (URL, buffers, timeouts, reconnect) is delegated to the
/// framework's <see cref="AcSignalRConnectionExtensions.AddAcConnection"/>, driven by
/// <see cref="AcHubConnectionOptions"/> from <c>appsettings.json</c>. The logger is supplied
/// by the caller (typically via a DI-registered <c>Func&lt;string, AcLoggerBase&gt;</c> factory
/// in <c>Program.cs</c>), keeping this extension free of <c>LoggerClient</c> construction.
/// </para>
/// </summary>
public static class FruitBankHubConnectionExtensions
{
    /// <summary>
    /// Applies <see cref="AcSignalRConnectionExtensions.AddAcConnection"/> with the given
    /// <paramref name="connectionOptions"/>, then bridges <paramref name="logger"/> into
    /// SignalR's internal <c>ILogger</c> pipeline.
    /// </summary>
    public static IHubConnectionBuilder AddFruitBankDefaults(this IHubConnectionBuilder builder, AcLoggerBase logger, AcHubConnectionOptions connectionOptions)
    {
        return builder
            .AddAcConnection(connectionOptions)
            .ConfigureLogging(logging =>
            {
                logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Information);
                logging.AddAcLogger(_ => logger);
            });
    }
}
