namespace ZB.MOM.WW.OtOpcUa.Core.Scripting;

/// <summary>
///     DI-friendly holder for the root script <see cref="Serilog.ILogger"/> so it can be
///     injected into the Roslyn evaluators without clashing with the application's main
///     <c>Serilog.Log.Logger</c> (both are <see cref="Serilog.ILogger"/>; a wrapper type
///     gives the container an unambiguous registration to resolve).
/// </summary>
/// <remarks>
///     The wrapped logger is the composed script pipeline — a rolling <c>scripts-*.log</c>
///     file sink, the <see cref="ScriptLogCompanionSink"/> mirroring errors to the main log,
///     and the <see cref="ScriptLogTopicSink"/> fanning entries onto the cluster
///     <c>script-logs</c> topic for the live Script-log Admin UI page.
///     <para>
///         Implements <see cref="IDisposable"/> so the DI container flushes the rolling-file
///         sink on graceful host shutdown.
///     </para>
/// </remarks>
public sealed class ScriptRootLogger : IDisposable
{
    private readonly Serilog.Core.Logger _logger;

    /// <summary>The composed root script logger (file + companion mirror + DPS topic sink).</summary>
    public Serilog.ILogger Logger => _logger;

    /// <summary>Initializes a new <see cref="ScriptRootLogger"/>.</summary>
    /// <param name="logger">The composed Serilog logger; owned + disposed by this wrapper.</param>
    public ScriptRootLogger(Serilog.Core.Logger logger) =>
        _logger = logger ?? throw new ArgumentNullException(nameof(logger));

    /// <summary>Disposes the underlying logger, flushing the rolling-file sink.</summary>
    public void Dispose() => _logger.Dispose();
}
