namespace ZB.MOM.WW.OtOpcUa.Driver.FOCAS.Supervisor;

/// <summary>
///     Abstraction over the act of spawning a FOCAS Host process and obtaining an
///     <see cref="IFocasClient"/> connected to it. Production wires this to a real
///     <c>Process.Start</c> + <c>FocasIpcClient.ConnectAsync</c>; tests use a fake that
///     exposes deterministic failure modes so the supervisor logic can be stressed
///     without spawning actual exes.
/// </summary>
public interface IHostProcessLauncher
{
    /// <summary>
    ///     Spawn a new Host process (if one isn't already running) and return a live
    ///     client session. Throws on unrecoverable errors; transient errors (e.g. Host
    ///     not ready yet) should throw <see cref="TimeoutException"/> so the supervisor
    ///     applies the backoff ladder.
    /// </summary>
    Task<IFocasClient> LaunchAsync(CancellationToken ct);

    /// <summary>
    ///     Terminate the Host process if one is running. Called on Dispose and after a
    ///     heartbeat loss is detected.
    /// </summary>
    Task TerminateAsync(CancellationToken ct);

    /// <summary>
    ///     <c>true</c> when the most recently spawned Host process is still alive.
    ///     Supervisor polls this at heartbeat cadence; going <c>false</c> without a
    ///     clean shutdown counts as a crash.
    /// </summary>
    bool IsProcessAlive { get; }
}
