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

namespace skyscraper8.Ieee802_1AB.Model;

public class LldpChassis
{
    public LldpChassis(byte[] value)
    {
        MemoryStream ms = new MemoryStream(value);
        ChassisSubtype = ms.ReadUInt8();
        switch (ChassisSubtype)
        {
            case 4:
                MacAddress = new PhysicalAddress(ms.ReadBytes(6));
                break;
            default:
                throw new NotImplementedException(string.Format("Chassis Subtype {0} not yet supported. Please share a sample of this stream.", ChassisSubtype));
        }
    }

    public PhysicalAddress MacAddress { get; set; }

    public byte ChassisSubtype { get; private set; }

    protected bool Equals(LldpChassis other)
    {
	    return MacAddress.Equals(other.MacAddress) && ChassisSubtype == other.ChassisSubtype;
    }

    public override bool Equals(object? obj)
    {
	    if (ReferenceEquals(null, obj)) 
		    return false;
	    if (ReferenceEquals(this, obj)) 
		    return true;
	    if (obj.GetType() != this.GetType())
		    return false;
	    return Equals((LldpChassis)obj);
    }

    public override int GetHashCode()
    {
	    return HashCode.Combine(MacAddress, ChassisSubtype);
    }

    public override string ToString()
    {
	    switch (ChassisSubtype)
	    {
            case 4:
	            return MacAddress.ToString();
		    default:
			    return String.Format("Chassis Subtype {0}", ChassisSubtype);
	    }
    }
}