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

/// <summary>
///     Abstraction over OS process enumeration and termination. Exists so the
///     orphan-worker cleanup logic can be unit-tested without spawning real
///     processes.
/// </summary>
public interface IRunningProcessInspector
{
    /// <summary>
    ///     Enumerates currently running processes whose image name (without the
    ///     <c>.exe</c> extension) matches <paramref name="processName"/>.
    /// </summary>
    /// <param name="processName">Process image name to match, without extension.</param>
    /// <returns>The matching running processes.</returns>
    IReadOnlyList<RunningProcessInfo> GetProcessesByName(string processName);

    /// <summary>Forcibly terminates the process with the given identifier.</summary>
    /// <param name="processId">Identifier of the process to terminate.</param>
    void Kill(int processId);
}

/// <summary>Identifying information for a running process candidate.</summary>
/// <param name="ProcessId">Operating-system process identifier.</param>
/// <param name="ExecutablePath">
///     Fully-qualified path to the process main module, or <see langword="null"/>
///     when it could not be read (e.g. access denied).
/// </param>
public sealed record RunningProcessInfo(int ProcessId, string? ExecutablePath);
