using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class LeCreateBigInfo : PacketInfoBase
{
	public override string Name => "Le Create Big";

	public override string DisplayGroup => "LE Controller";

	public LeCreateBigInfo(LeCreateBig packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		LeCreateBig leCreateBig = (LeCreateBig)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("BIG_Handle", "Used to identify the Broadcast Isochronous Group.", 8, FormatValue(leCreateBig.UserFields.BigHandle, 8), "", "0", "EF", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Advertising_Handle", "Used to identify the Periodic Advertising set.", 8, FormatValue(leCreateBig.UserFields.AdvertisingHandle, 8), "", "0", "EF", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Num_BIS", "Total number of BIS in the BIG.", 8, FormatValue(leCreateBig.UserFields.NumBis, 8), "", "1", "1F", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("SDU_Interval", "Interval of periodic SDUs in microseconds .", 24, FormatValue(leCreateBig.UserFields.SduInterval, 24), "", "100", "FFFFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Max_SDU", "Maximum size of a SDU.", 16, FormatValue(leCreateBig.UserFields.MaxSdu, 16), "", "0", "FFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Max_Transport_Latency", "The maximum time in milliseconds for every Data PDU to be transmitted.", 16, FormatValue(leCreateBig.UserFields.MaxTransportLatency, 16), "", "0000", "0FA0", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("RTN", "Maximum number of times every Data PDU of a BIS is retransmitted.", 8, FormatValue(leCreateBig.UserFields.Rtn, 8), "", "0", "F", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("PHY", TransmitterPhyPreferenceInfo.TransmitterPhyPreferenceToDescription(), 8, FormatValue(leCreateBig.UserFields.Phy, 8), TransmitterPhyPreferenceInfo.TransmitterPhyPreferenceToString(TransmitterPhyPreferenceInfo.ValueToTransmitterPhyPreference(leCreateBig.UserFields.Phy)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Packing", IsoPackingInfo.IsoPackingToDescription(), 8, FormatValue(leCreateBig.UserFields.Packing, 8), IsoPackingInfo.IsoPackingToString(IsoPackingInfo.ValueToIsoPacking(leCreateBig.UserFields.Packing)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Framing", IsoFramingInfo.IsoFramingToDescription(), 8, FormatValue(leCreateBig.UserFields.Framing, 8), IsoFramingInfo.IsoFramingToString(IsoFramingInfo.ValueToIsoFraming(leCreateBig.UserFields.Framing)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Encryption", IsoEncryptionInfo.IsoEncryptionToDescription(), 8, FormatValue(leCreateBig.UserFields.Encryption, 8), IsoEncryptionInfo.IsoEncryptionToString(IsoEncryptionInfo.ValueToIsoEncryption(leCreateBig.UserFields.Encryption)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("BroadcastCode", "The code used to derive the session key that is used to encrypt and decrypt BIS payloads.", leCreateBig.UserFields.BroadcastcodeList.Count * 8, FormatValue(leCreateBig.UserFields.BroadcastcodeList, leCreateBig.UserFields.BroadcastcodeList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		LeCreateBig leCreateBig = (LeCreateBig)packet;
		int num = -1;
		if (index == ++num)
		{
			leCreateBig.UserFields.BigHandle = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leCreateBig.UserFields.AdvertisingHandle = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leCreateBig.UserFields.NumBis = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leCreateBig.UserFields.SduInterval = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leCreateBig.UserFields.MaxSdu = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leCreateBig.UserFields.MaxTransportLatency = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leCreateBig.UserFields.Rtn = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leCreateBig.UserFields.Phy = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leCreateBig.UserFields.Packing = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leCreateBig.UserFields.Framing = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leCreateBig.UserFields.Encryption = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			value = AddLeadingZerosAndCheckValueStringLength(value, leCreateBig.UserFields.BroadcastcodeList.Count);
			int num2 = 0;
			while (value.Length > 0)
			{
				string value2 = value.Substring(0, 2);
				value = value.Remove(0, 2);
				leCreateBig.UserFields.BroadcastcodeList[num2] = Convert.ToUInt32(value2, 16);
				num2++;
			}
		}
	}
}
