using System.Diagnostics;

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

/// <summary>
/// Factory that creates system processes for workers.
/// </summary>
public sealed class SystemWorkerProcessFactory : IWorkerProcessFactory
{
    /// <inheritdoc />
    public IWorkerProcess Start(ProcessStartInfo startInfo)
    {
        Process process = new()
        {
            StartInfo = startInfo,
        };

        if (!process.Start())
        {
            process.Dispose();
            throw new InvalidOperationException("Worker process failed to start.");
        }

        return new SystemWorkerProcess(process);
    }
}
