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 TCP logger with an <see cref="ILoggingBuilder"/>.
    /// </summary>
    public static class TcpLoggerFactoryExtensions
    {
        /// <summary>
        /// Adds a TCP-based logger provider to the logging builder, allowing log messages to be sent over TCP using the
        /// specified configuration.
        /// </summary>
        /// <remarks>Use this method to enable logging to a remote endpoint over TCP. The <paramref
        /// name="configure"/> action allows customization of connection settings and other logger options.</remarks>
        /// <param name="builder">The logging builder to which the TCP logger provider will be added.</param>
        /// <param name="configure">An action to configure the TCP logger options. Cannot be null.</param>
        /// <returns>The same instance of <see cref="ILoggingBuilder"/> for chaining.</returns>
        public static ILoggingBuilder AddEonaCatTcpLogger(this ILoggingBuilder builder, Action<TcpLoggerOptions> configure)
        {
            var options = new TcpLoggerOptions();
            configure?.Invoke(options);

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

}
