using System.Net;
using skyscraper5.Skyscraper.IO;

namespace skyscraper8.Ieee802_1AB.Model;

public class LldpManagementAddress
{
    public LldpManagementAddress(byte[] buffer)
    {
        MemoryStream ms = new MemoryStream(buffer, false);
        byte managementAddressStringLength = ms.ReadUInt8();
        ManagementAddressSubtype = ms.ReadUInt8();
        managementAddressStringLength--;

        if (ManagementAddressSubtype != 1)
        {
            throw new NotImplementedException("Unknown management address subtype. Please share a sample of this stream.");
        }

        ManagementAddress = new IPAddress(ms.ReadBytes(managementAddressStringLength));
        InterfaceNumberingSubtype = ms.ReadUInt8();
        InterfaceNumber = ms.ReadUInt32BE();
        
        byte oidStringLength = ms.ReadUInt8();
        ObjectIdentifier = ms.ReadBytes(oidStringLength);
    }

    public byte[] ObjectIdentifier { get; set; }

    public uint InterfaceNumber { get; set; }

    public byte InterfaceNumberingSubtype { get; set; }

    public byte ManagementAddressSubtype { get; set; }

    public IPAddress ManagementAddress { get; set; }
}