namespace SHH.ProcessLaunchers
{
    /// <summary>
    /// 启动器专用日志接口
    /// <para>核心职责：解耦日志的生产与消费，支持结构化语义记录。</para>
    /// <para>实现类可将日志转发至 UI 控制台、本地文件或远程日志中心。</para>
    /// </summary>
    public interface ILauncherLogger
    {
        /// <summary>
        /// 记录普通控制台日志 (流式日志)
        /// <para>用于接管子进程的 StdOut 和 StdErr</para>
        /// </summary>
        /// <param name="processId">进程唯一标识 (ProcessConfig.Id)</param>
        /// <param name="message">日志内容</param>
        /// <param name="isError">是否为错误流 (True=StdErr, False=StdOut)</param>
        void LogConsole(string processId, string message, bool isError);

        /// <summary>
        /// 记录关键生命周期事件 (结构化日志)
        /// <para>用于记录启停、崩溃、熔断等关键节点，供运维分析。</para>
        /// </summary>
        /// <param name="processId">进程唯一标识 (ProcessConfig.Id)</param>
        /// <param name="action">动作类型 (Start/Stop/Crash...)</param>
        /// <param name="trigger">触发源 (User/System...)</param>
        /// <param name="reason">操作原因或备注 (必填，用于追溯)</param>
        /// <param name="payload">附加上下文对象 (可选，如 { PID=123, ExitCode=-1 })</param>
        void LogLifecycle(string processId, LogAction action, LogTrigger trigger, string reason, object payload = null);
    }

    /// <summary>
    /// 默认空日志实现 (Null Object Pattern)
    /// <para>用于在未注入 Logger 时防止 NullReferenceException，保证程序健壮性。</para>
    /// </summary>
    public class NullLogger : ILauncherLogger
    {
        /// <summary>
        /// 空实现：忽略控制台日志
        /// </summary>
        public void LogConsole(string processId, string message, bool isError)
        {
            // Do nothing
        }

        /// <summary>
        /// 空实现：忽略生命周期日志
        /// </summary>
        public void LogLifecycle(string processId, LogAction action, LogTrigger trigger, string reason, object payload = null)
        {
            // Do nothing
        }
    }
}