using TeamsISO.Engine.Interop;

namespace TeamsISO.Engine.NdiInterop;

internal sealed class NdiPInvokeFindHandle : NdiFindHandle
{
    public IntPtr Native { get; private set; }

    public NdiPInvokeFindHandle(IntPtr native) => Native = native;

    public override void Dispose()
    {
        if (Native != IntPtr.Zero)
        {
            NdiNative.FindDestroy(Native);
            Native = IntPtr.Zero;
        }
    }
}

internal sealed class NdiPInvokeReceiverHandle : NdiReceiverHandle
{
    public IntPtr Native { get; private set; }
    public string SourceName { get; }

    public NdiPInvokeReceiverHandle(IntPtr native, string sourceName)
    {
        Native = native;
        SourceName = sourceName;
    }

    public override void Dispose()
    {
        if (Native != IntPtr.Zero)
        {
            NdiNative.RecvDestroy(Native);
            Native = IntPtr.Zero;
        }
    }
}

internal sealed class NdiPInvokeSenderHandle : NdiSenderHandle
{
    public IntPtr Native { get; private set; }
    public string OutputName { get; }

    public NdiPInvokeSenderHandle(IntPtr native, string outputName)
    {
        Native = native;
        OutputName = outputName;
    }

    public override void Dispose()
    {
        if (Native != IntPtr.Zero)
        {
            NdiNative.SendDestroy(Native);
            Native = IntPtr.Zero;
        }
    }
}
