using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System;

namespace EonaCat.Logger.EonaCatCoreLogger.Extensions
{
    /// <summary>
    /// Provides extension methods for registering a Discord logger with an <see cref="ILoggingBuilder"/>.
    /// </summary>
    /// <remarks>These extensions enable logging to Discord by adding a custom logger provider to the
    /// application's logging pipeline. Use these methods to configure and enable Discord-based logging within your
    /// application's logging setup.</remarks>
    public static class DiscordLoggerFactoryExtensions
    {
        /// <summary>
        /// Adds a logger that sends log messages to Discord using the EonaCat Discord Logger provider.
        /// </summary>
        /// <remarks>Call this method to enable logging to a Discord channel via the EonaCat Discord
        /// Logger. The <paramref name="configure"/> delegate allows customization of logger options such as webhook URL
        /// and log level filtering.</remarks>
        /// <param name="builder">The logging builder to which the Discord logger provider will be added.</param>
        /// <param name="configure">A delegate to configure the options for the Discord logger. Cannot be null.</param>
        /// <returns>The same instance of <see cref="ILoggingBuilder"/> for chaining.</returns>
        public static ILoggingBuilder AddEonaCatDiscordLogger(this ILoggingBuilder builder, Action<DiscordLoggerOptions> configure)
        {
            var options = new DiscordLoggerOptions();
            configure?.Invoke(options);

            builder.Services.AddSingleton<ILoggerProvider>(new DiscordLoggerProvider(options));
            return builder;
        }
    }
}
