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

namespace Decal.DecalNet
{
    [ComVisible(true)]
    [ClassInterface(ClassInterfaceType.None)]
    public class MessageImpl : IMessage2
    {
        private readonly byte[] _rawData;
        private readonly int _type;
        private readonly bool _outgoing;

        public MessageImpl(byte[] rawData, bool outgoing)
        {
            _rawData = rawData ?? Array.Empty<byte>();
            _outgoing = outgoing;

            // Message type is the first DWORD in the raw data
            if (_rawData.Length >= 4)
                _type = BitConverter.ToInt32(_rawData, 0);
        }

        public int Type => _type;

        public byte[] RawData => _rawData;

        // Parameterized property - Value takes an index via IDispatch
        public object Value => null;

        // Parameterized property - Struct takes an index via IDispatch
        public IMessageMember Struct => null;

        // Parameterized property
        public byte[] RawValue => _rawData;

        // Parameterized property
        public string FieldName => string.Empty;

        public int Count => 0;

        public MessageRoot Begin => null;
    }
}
