using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class A2dpSinkStartInfo : PacketInfoBase
{
	public override string Name => "A2dp Sink Start";

	public override string DisplayGroup => "Vendor Specific";

	public A2dpSinkStartInfo(A2dpSinkStart packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		A2dpSinkStart a2dpSinkStart = (A2dpSinkStart)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Sub OpCode", A2dpSinkStart.UserFieldsWrapper.SubOpcodeInfo.SubOpcodeToDescription(), 8, FormatValue(a2dpSinkStart.UserFields.SubOpcode, 8), A2dpSinkStart.UserFieldsWrapper.SubOpcodeInfo.SubOpcodeToString(A2dpSinkStart.UserFieldsWrapper.SubOpcodeInfo.ValueToSubOpcode(a2dpSinkStart.UserFields.SubOpcode)), "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Stream_Handle", "Stream Handle for A2DP sink stream", 8, FormatValue(a2dpSinkStart.UserFields.StreamHandle, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Connection_Handle", "ACL connection handle", 16, FormatValue(a2dpSinkStart.UserFields.ConnectionHandle, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("LCID", "L2CAP channel identifier", 16, FormatValue(a2dpSinkStart.UserFields.Lcid, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Codec_ID", "Negotiated coded identifier", 8, FormatValue(a2dpSinkStart.UserFields.CodecId, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Peak_Bit_Rate", "Peak bit rate in bps", 24, FormatValue(a2dpSinkStart.UserFields.PeakBitRate, 24), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.DecimalInteger));
		fieldInfoList.Add(new PacketFieldInfo("L2CAP_MTU", "L2CAP MTU for the streaming channel", 16, FormatValue(a2dpSinkStart.UserFields.L2capMtu, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Packet_Header_Size", "Bytes in L2CAP payload before encoded frame", 8, FormatValue(a2dpSinkStart.UserFields.PacketHeaderSize, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		A2dpSinkStart a2dpSinkStart = (A2dpSinkStart)packet;
		int num = -1;
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field SubOpcode");
		}
		if (index == ++num)
		{
			a2dpSinkStart.UserFields.StreamHandle = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			a2dpSinkStart.UserFields.ConnectionHandle = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			a2dpSinkStart.UserFields.Lcid = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			a2dpSinkStart.UserFields.CodecId = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			a2dpSinkStart.UserFields.PeakBitRate = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			a2dpSinkStart.UserFields.L2capMtu = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			a2dpSinkStart.UserFields.PacketHeaderSize = Convert.ToUInt32(value, 16);
		}
	}
}
