using System.Runtime.InteropServices;
using Decal.Interop.Filters;
using Decal.Interop.Net;

namespace Decal.DecalFilters
{
    [ComVisible(true)]
    [Guid("8C2FA400-315D-41DE-B063-D6EF04F12E1F")]
    [ClassInterface(ClassInterfaceType.None)]
    [ComSourceInterfaces("Decal.Interop.Filters.IEchoSink\0\0")]
    [ProgId("DecalFilters.EchoFilter")]
    public class EchoFilterImpl : IEcho, INetworkFilter2
    {
        public event IEchoSink_EchoMessageEventHandler EchoMessage;

        public void Initialize(NetService pService) { }
        public void Terminate() { }

        public void DispatchServer(IMessage2 Message)
        {
            // V1 echo passes IMessage, not IMessage2
            EchoMessage?.Invoke((IMessage)Message);
        }

        public void DispatchClient(IMessage2 Message)
        {
            EchoMessage?.Invoke((IMessage)Message);
        }
    }

    [ComVisible(true)]
    [Guid("34239EAD-6317-4c40-A405-193BA5232DD8")]
    [ClassInterface(ClassInterfaceType.None)]
    [ComSourceInterfaces("Decal.Interop.Filters.IEchoSink2\0\0")]
    [ProgId("DecalFilters.EchoFilter2")]
    public class EchoFilter2Impl : IEcho2, INetworkFilter2
    {
        public event IEchoSink2_EchoServerEventHandler EchoServer;
        public event IEchoSink2_EchoClientEventHandler EchoClient;

        public void Initialize(NetService pService) { }
        public void Terminate() { }

        public void DispatchServer(IMessage2 Message)
        {
            EchoServer?.Invoke(Message);
        }

        public void DispatchClient(IMessage2 Message)
        {
            EchoClient?.Invoke(Message);
        }
    }
}
