using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class A2dpWriteA2dpConfigInfo : PacketInfoBase
{
	public override string Name => "A2dp Write A2dp Config";

	public override string DisplayGroup => "Vendor Specific";

	public A2dpWriteA2dpConfigInfo(A2dpWriteA2dpConfig packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		A2dpWriteA2dpConfig a2dpWriteA2dpConfig = (A2dpWriteA2dpConfig)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Sub OpCode", "", 8, FormatValue(a2dpWriteA2dpConfig.UserFields.SubOpcode, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Codec", "Selected Codec\r\n\r\n" + CodecTypesInfo.CodecTypesToDescription(), 8, FormatValue(a2dpWriteA2dpConfig.UserFields.Codec, 8), CodecTypesInfo.CodecTypesToString(CodecTypesInfo.ValueToCodecTypes(a2dpWriteA2dpConfig.UserFields.Codec)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Transport", "Transport Type\r\n\r\n" + A2dpWriteA2dpConfig.UserFieldsWrapper.TransportInfo.TransportToDescription(), 8, FormatValue(a2dpWriteA2dpConfig.UserFields.Transport, 8), A2dpWriteA2dpConfig.UserFieldsWrapper.TransportInfo.TransportToString(A2dpWriteA2dpConfig.UserFieldsWrapper.TransportInfo.ValueToTransport(a2dpWriteA2dpConfig.UserFields.Transport)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Transport Stream Type", "Transport Stream Type\r\n\r\n" + CodecTypesInfo.CodecTypesToDescription(), 8, FormatValue(a2dpWriteA2dpConfig.UserFields.TransportStreamType, 8), CodecTypesInfo.CodecTypesToString(CodecTypesInfo.ValueToCodecTypes(a2dpWriteA2dpConfig.UserFields.TransportStreamType)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Stream Handle", "Handle", 8, FormatValue(a2dpWriteA2dpConfig.UserFields.StreamHandle, 8), "", "", "1", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Max Latency", "Max Latency Allowed (ms)", 8, FormatValue(a2dpWriteA2dpConfig.UserFields.MaxLatency, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Delay Report Enable", "Enable Delay Reporting", 8, FormatValue(a2dpWriteA2dpConfig.UserFields.DelayReportEnable, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("SCMS-T Enable", "Enable SCMS-T", 8, FormatValue(a2dpWriteA2dpConfig.UserFields.ScmsTEnable, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("SCMS-T Header", "SCMS-T Header Value", 8, FormatValue(a2dpWriteA2dpConfig.UserFields.ScmsTHeader, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Sampling Frequency", "Sampling Frequency", 16, FormatValue(a2dpWriteA2dpConfig.UserFields.SamplingFrequency, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Connection_handle", "Identifies the Split A2DP connection", 16, FormatValue(a2dpWriteA2dpConfig.UserFields.ConnectionHandle, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("L2CAP CID", "L2CAP Connection ID", 16, FormatValue(a2dpWriteA2dpConfig.UserFields.L2capCid, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("L2CAP MTU Size", "L2CAP MTU Size", 16, FormatValue(a2dpWriteA2dpConfig.UserFields.L2capMtuSize, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Start Stream", "Start Stream Now\r\n\r\n" + A2dpWriteA2dpConfig.UserFieldsWrapper.StartStreamInfo.StartStreamToDescription(), 8, FormatValue(a2dpWriteA2dpConfig.UserFields.StartStream, 8), A2dpWriteA2dpConfig.UserFieldsWrapper.StartStreamInfo.StartStreamToString(A2dpWriteA2dpConfig.UserFieldsWrapper.StartStreamInfo.ValueToStartStream(a2dpWriteA2dpConfig.UserFields.StartStream)), "", "01", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("TWS Enable", "TWS+ Earbud Mode Enable\r\n\r\n" + A2dpWriteA2dpConfig.UserFieldsWrapper.TwsEnableInfo.TwsEnableToDescription(), 8, FormatValue(a2dpWriteA2dpConfig.UserFields.TwsEnable, 8), A2dpWriteA2dpConfig.UserFieldsWrapper.TwsEnableInfo.TwsEnableToString(A2dpWriteA2dpConfig.UserFieldsWrapper.TwsEnableInfo.ValueToTwsEnable(a2dpWriteA2dpConfig.UserFields.TwsEnable)), "", "01", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Channel Mode", "Channel Mode\r\n\r\n" + A2dpWriteA2dpConfig.UserFieldsWrapper.ChannelModeInfo.ChannelModeToDescription(), 8, FormatValue(a2dpWriteA2dpConfig.UserFields.ChannelMode, 8), A2dpWriteA2dpConfig.UserFieldsWrapper.ChannelModeInfo.ChannelModeToString(A2dpWriteA2dpConfig.UserFieldsWrapper.ChannelModeInfo.ValueToChannelMode(a2dpWriteA2dpConfig.UserFields.ChannelMode)), "", "03", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("TTP Offset", "Time To Play Offset in ms", 16, FormatValue(a2dpWriteA2dpConfig.UserFields.TtpOffset, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Codec Info", "Contents are codec-specific. Contains max of 20 bytes.", a2dpWriteA2dpConfig.UserFields.CodecInfoList.Count * 8, FormatValue(a2dpWriteA2dpConfig.UserFields.CodecInfoList, a2dpWriteA2dpConfig.UserFields.CodecInfoList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		A2dpWriteA2dpConfig a2dpWriteA2dpConfig = (A2dpWriteA2dpConfig)packet;
		int num = -1;
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field SubOpcode");
		}
		if (index == ++num)
		{
			a2dpWriteA2dpConfig.UserFields.Codec = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			a2dpWriteA2dpConfig.UserFields.Transport = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			a2dpWriteA2dpConfig.UserFields.TransportStreamType = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			a2dpWriteA2dpConfig.UserFields.StreamHandle = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			a2dpWriteA2dpConfig.UserFields.MaxLatency = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			a2dpWriteA2dpConfig.UserFields.DelayReportEnable = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			a2dpWriteA2dpConfig.UserFields.ScmsTEnable = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			a2dpWriteA2dpConfig.UserFields.ScmsTHeader = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			a2dpWriteA2dpConfig.UserFields.SamplingFrequency = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			a2dpWriteA2dpConfig.UserFields.ConnectionHandle = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			a2dpWriteA2dpConfig.UserFields.L2capCid = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			a2dpWriteA2dpConfig.UserFields.L2capMtuSize = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			a2dpWriteA2dpConfig.UserFields.StartStream = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			a2dpWriteA2dpConfig.UserFields.TwsEnable = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			a2dpWriteA2dpConfig.UserFields.ChannelMode = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			a2dpWriteA2dpConfig.UserFields.TtpOffset = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			value = AddLeadingZerosAndCheckValueStringLength(value, a2dpWriteA2dpConfig.UserFields.CodecInfoList.Count);
			int num2 = 0;
			while (value.Length > 0)
			{
				string value2 = value.Substring(0, 2);
				value = value.Remove(0, 2);
				a2dpWriteA2dpConfig.UserFields.CodecInfoList[num2] = Convert.ToUInt32(value2, 16);
				num2++;
			}
		}
	}
}
