using System;

namespace SHH.ProcessLaunchers
{
    /// <summary>
    /// 进程输出事件参数 (StdOut/StdErr)
    /// </summary>
    public class ProcessOutputEventArgs : EventArgs
    {
        /// <summary>进程唯一标识 (ID)</summary>
        public string ProcessId { get; set; } = string.Empty;

        /// <summary>来源进程名称</summary>
        public string ProcessName { get; set; } = string.Empty;

        /// <summary>输出内容</summary>
        public string Content { get; set; } = string.Empty;

        /// <summary>是否为错误流 (StdErr)</summary>
        public bool IsError { get; set; }
    }

    /// <summary>
    /// 进程状态变更事件参数
    /// </summary>
    public class ProcessStateEventArgs : EventArgs
    {
        /// <summary>进程唯一标识 (ID)</summary>
        public string ProcessId { get; set; } = string.Empty;

        /// <summary>来源进程名称</summary>
        public string ProcessName { get; set; } = string.Empty;

        /// <summary>变更后的新状态</summary>
        public ProcessStatus State { get; set; }
    }

    /// <summary>
    /// 进程生命周期状态枚举
    /// </summary>
    public enum ProcessStatus
    {
        /// <summary>已停止 (初始状态或用户手动停止)</summary>
        Stopped,

        /// <summary>启动中 (正在初始化进程对象)</summary>
        Starting,

        /// <summary>运行中 (PID 已存在)</summary>
        Running,

        /// <summary>等待重启 (崩溃后的短暂停留，默认3秒)</summary>
        PendingRestart,

        /// <summary>熔断冷却中 (连续失败多次后的长时间等待，默认30分钟)</summary>
        CoolingDown
    }

    /// <summary>
    /// 资源哨兵检查结果枚举
    /// </summary>
    public enum GuardResult
    {
        /// <summary>一切正常</summary>
        Normal,

        /// <summary>警告 (有点问题，建议记录日志或发邮件，但不杀进程)</summary>
        Warning,

        /// <summary>严重故障 (必须立即重启进程以保护系统)</summary>
        Critical
    }

    /// <summary>
    /// 操作归因：定义是谁/什么触发了这个动作
    /// <para>用于后续分析是人为操作还是系统自愈</para>
    /// </summary>
    public enum LogTrigger
    {
        /// <summary>
        /// 用户手动干预 (UI点击、API调用)
        /// <para>优先级：最高。通常视为预期内操作。</para>
        /// </summary>
        User,

        /// <summary>
        /// 启动器自愈行为 (崩溃重启、初始化启动、熔断恢复)
        /// <para>优先级：高。代表系统正在尝试维持服务。</para>
        /// </summary>
        System,

        /// <summary>
        /// 资源哨兵触发 (内存/CPU超限)
        /// <para>优先级：紧急。代表出现了亚健康状态或强制管控。</para>
        /// </summary>
        ResourceGuard,

        /// <summary>
        /// 定时任务/计划调度
        /// <para>优先级：中。代表按计划执行的任务。</para>
        /// </summary>
        Scheduler
    }

    /// <summary>
    /// 核心动作类型
    /// <para>定义进程生命周期中发生了什么具体的事件</para>
    /// </summary>
    public enum LogAction
    {
        /// <summary>启动进程</summary>
        Start,

        /// <summary>停止进程</summary>
        Stop,

        /// <summary>重启进程</summary>
        Restart,

        /// <summary>侦测到意外退出</summary>
        Crash,

        /// <summary>标准输出流 (StdOut) - 通常是程序打印的普通日志</summary>
        Output,

        /// <summary>标准错误流 (StdErr) - 程序打印的异常或错误</summary>
        Error,

        /// <summary>触发熔断保护 (停止重试)</summary>
        CircuitBreak,

        /// <summary>资源检查警告 (如内存超限报警，但不重启)</summary>
        ResourceCheck
    }
}