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

// This file is part of the EonaCat project(s) which is released under the Apache License.
// See the LICENSE file or go to https://EonaCat.com/License for full license details.

namespace EonaCat.Logger.EonaCatCoreLogger.Extensions
{
    /// <summary>
    /// Provides extension methods for registering the EonaCat HTTP logger with an <see cref="ILoggingBuilder"/>.
    /// </summary>
    /// <remarks>This class contains extension methods that enable integration of the EonaCat HTTP logger into
    /// the logging pipeline using dependency injection. These methods are intended to be used during application
    /// startup when configuring logging services.</remarks>
    public static class HttpLoggerFactoryExtensions
    {
        /// <summary>
        /// Adds an HTTP logger provider to the logging builder, allowing log messages to be sent over HTTP with
        /// configurable options.
        /// </summary>
        /// <remarks>Use this method to enable logging to an HTTP endpoint by configuring the <see
        /// cref="HttpLoggerOptions"/>. This method should be called as part of the logging setup in your application's
        /// dependency injection configuration.</remarks>
        /// <param name="builder">The logging builder to which the HTTP logger provider will be added.</param>
        /// <param name="configure">An action to configure the HTTP logger options. This parameter cannot be null.</param>
        /// <returns>The same instance of <see cref="ILoggingBuilder"/> for chaining.</returns>
        public static ILoggingBuilder AddEonaCatHttpLogger(this ILoggingBuilder builder, Action<HttpLoggerOptions> configure)
        {
            var options = new HttpLoggerOptions();
            configure?.Invoke(options);
            builder.Services.AddSingleton<ILoggerProvider>(new HttpLoggerProvider(options));
            return builder;
        }
    }

}
