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

namespace EonaCat.Logger.EonaCatCoreLogger.Extensions
{
    /// <summary>
    /// Provides extension methods for registering the EonaCat Telegram logger with an <see cref="ILoggingBuilder"/>.
    /// </summary>
    /// <remarks>These extension methods enable integration of Telegram-based logging into applications using
    /// Microsoft.Extensions.Logging. Use these methods to configure and add the EonaCat Telegram logger provider to the
    /// logging pipeline.</remarks>
    public static class TelegramLoggerFactoryExtensions
    {
        /// <summary>
        /// Adds a Telegram-based logger to the logging builder using the specified configuration options.
        /// </summary>
        /// <remarks>Use this method to enable logging to Telegram by configuring the required options,
        /// such as bot token and chat ID. This logger allows log messages to be sent directly to a Telegram
        /// chat.</remarks>
        /// <param name="builder">The logging builder to which the Telegram logger will be added.</param>
        /// <param name="configure">An action to configure the Telegram logger options. Cannot be null.</param>
        /// <returns>The same instance of <see cref="ILoggingBuilder"/> for chaining.</returns>
        public static ILoggingBuilder AddEonaCatTelegramLogger(this ILoggingBuilder builder, Action<TelegramLoggerOptions> configure)
        {
            var options = new TelegramLoggerOptions();
            configure?.Invoke(options);

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