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

namespace EonaCat.Logger.EonaCatCoreLogger.Extensions
{
    /// <summary>
    /// Provides extension methods for registering the EonaCat Slack logger with an <see cref="ILoggingBuilder"/>.
    /// </summary>
    /// <remarks>These extension methods enable integration of Slack-based logging into applications using
    /// Microsoft.Extensions.Logging. Use these methods to configure and add the EonaCat Slack logger provider to the
    /// logging pipeline.</remarks>
    public static class SlackLoggerFactoryExtensions
    {
        /// <summary>
        /// Adds a Slack-based logger to the logging builder, allowing log messages to be sent to Slack using the
        /// specified configuration.
        /// </summary>
        /// <remarks>Call this method to enable logging to Slack within your application's logging
        /// pipeline. The provided configuration action allows you to specify Slack webhook URLs and other logger
        /// options. This method registers the Slack logger as a singleton service.</remarks>
        /// <param name="builder">The logging builder to which the Slack logger will be added.</param>
        /// <param name="configure">An action to configure the Slack logger options. Cannot be null.</param>
        /// <returns>The same instance of <see cref="ILoggingBuilder"/> for chaining.</returns>
        public static ILoggingBuilder AddEonaCatSlackLogger(this ILoggingBuilder builder, Action<SlackLoggerOptions> configure)
        {
            var options = new SlackLoggerOptions();
            configure?.Invoke(options);

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