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

/// <summary>
/// Abstraction over a worker process with lifecycle and exit-code operations.
/// </summary>
public interface IWorkerProcess : IDisposable
{
    /// <summary>
    /// The process ID.
    /// </summary>
    int Id { get; }

    /// <summary>
    /// Indicates whether the process has exited.
    /// </summary>
    bool HasExited { get; }

    /// <summary>
    /// The exit code if the process has exited; otherwise null.
    /// </summary>
    int? ExitCode { get; }

    /// <summary>
    /// Waits for the process to exit with the specified cancellation token.
    /// </summary>
    /// <param name="cancellationToken">Token to cancel the asynchronous operation.</param>
    /// <returns>A task that represents the asynchronous operation.</returns>
    ValueTask WaitForExitAsync(CancellationToken cancellationToken);

    /// <summary>
    /// Kills the process, optionally terminating the entire process tree.
    /// </summary>
    /// <param name="entireProcessTree">If true, terminate all child processes; otherwise terminate only this process.</param>
    void Kill(bool entireProcessTree);
}
