namespace ZB.MOM.WW.MxGateway.Server.Workers;

/// <summary>Handle to a running worker process with metadata.</summary>
public sealed class WorkerProcessHandle : IDisposable
{
    /// <summary>Initializes a new instance of the WorkerProcessHandle class.</summary>
    /// <param name="process">The underlying worker process.</param>
    /// <param name="commandLine">The command line and arguments used to launch the process.</param>
    /// <param name="launchedAt">The time when the process was launched.</param>
    public WorkerProcessHandle(
        IWorkerProcess process,
        WorkerProcessCommandLine commandLine,
        DateTimeOffset launchedAt)
    {
        Process = process;
        ProcessId = process.Id;
        CommandLine = commandLine;
        LaunchedAt = launchedAt;
    }

    /// <summary>Gets the underlying worker process.</summary>
    public IWorkerProcess Process { get; }

    /// <summary>Gets the process ID.</summary>
    public int ProcessId { get; }

    /// <summary>Gets the command line and arguments used to launch the process.</summary>
    public WorkerProcessCommandLine CommandLine { get; }

    /// <summary>Gets the time when the process was launched.</summary>
    public DateTimeOffset LaunchedAt { get; }

    /// <summary>Disposes the underlying worker process.</summary>
    public void Dispose()
    {
        Process.Dispose();
    }
}
