namespace DragonISO.Engine.Interop;

/// <summary>
/// Result of an NDI runtime version check.
/// </summary>
public abstract record NdiRuntimeProbeResult
{
    public sealed record Match(string Version) : NdiRuntimeProbeResult;
    public sealed record Mismatch(string Detected, string Expected) : NdiRuntimeProbeResult;
}

/// <summary>
/// Compares the installed NDI runtime version (read via <see cref="INdiInterop.GetRuntimeVersion"/>)
/// against an expected prefix supplied at construction. Prefix matching is used because the NDI
/// runtime reports a longer string (e.g. "NDI SDK for Windows v6.0.1.0") and we typically only
/// care that the major SDK family is correct ("NDI SDK for Windows v6").
/// </summary>
public sealed class NdiRuntimeProbe
{
    private readonly INdiInterop _interop;
    private readonly string _expectedPrefix;

    public NdiRuntimeProbe(INdiInterop interop, string expectedVersion)
    {
        _interop = interop;
        _expectedPrefix = expectedVersion;
    }

    public NdiRuntimeProbeResult Probe()
    {
        var detected = _interop.GetRuntimeVersion();
        return detected.StartsWith(_expectedPrefix, StringComparison.Ordinal)
            ? new NdiRuntimeProbeResult.Match(detected)
            : new NdiRuntimeProbeResult.Mismatch(detected, _expectedPrefix);
    }
}
