using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

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

	public override string DisplayGroup => "LE Controller";

	public LeBigCreateSyncInfo(LeBigCreateSync packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		LeBigCreateSync leBigCreateSync = (LeBigCreateSync)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("BIG_Handle", "Used to identify the Broadcast Isochronous Group.", 8, FormatValue(leBigCreateSync.UserFields.BigHandle, 8), "", "0", "EF", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Sync_Handle", "Used as an identifier of the periodic advertising set.", 16, FormatValue(leBigCreateSync.UserFields.SyncHandle, 16), "", "0000", "0EFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Encryption", IsoEncryptionInfo.IsoEncryptionToDescription(), 8, FormatValue(leBigCreateSync.UserFields.Encryption, 8), IsoEncryptionInfo.IsoEncryptionToString(IsoEncryptionInfo.ValueToIsoEncryption(leBigCreateSync.UserFields.Encryption)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("BroadcastCode", "128-bit code used for deriving the session key for decrypting payloads of encrypted BISes.", leBigCreateSync.UserFields.BroadcastcodeList.Count * 8, FormatValue(leBigCreateSync.UserFields.BroadcastcodeList, leBigCreateSync.UserFields.BroadcastcodeList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("MSE", LeBigCreateSync.UserFieldsWrapper.MseInfo.MseToDescription(), 8, FormatValue(leBigCreateSync.UserFields.Mse, 8), LeBigCreateSync.UserFieldsWrapper.MseInfo.MseToString(LeBigCreateSync.UserFieldsWrapper.MseInfo.ValueToMse(leBigCreateSync.UserFields.Mse)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("BIG_Sync_Timeout", "", 16, FormatValue(leBigCreateSync.UserFields.BigSyncTimeout, 16), "", "000A", "4000", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Num_BIS", "Total number of Broadcast Isochronous Streams to synchronize to.", 8, FormatValue(leBigCreateSync.UserFields.NumBis, 8), "", "1", "1F", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		for (int i = 0; i < leBigCreateSync.UserFields.BissList.Count; i++)
		{
			fieldInfoList.Add(new PacketFieldInfo("BIS[" + i + "]", "", 8, FormatValue(leBigCreateSync.UserFields.BissList[i].Bis, 8), "", "1", "1F", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		}
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		LeBigCreateSync leBigCreateSync = (LeBigCreateSync)packet;
		int num = -1;
		if (index == ++num)
		{
			leBigCreateSync.UserFields.BigHandle = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			leBigCreateSync.UserFields.SyncHandle = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			leBigCreateSync.UserFields.Encryption = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			value = AddLeadingZerosAndCheckValueStringLength(value, leBigCreateSync.UserFields.BroadcastcodeList.Count);
			int num2 = 0;
			while (value.Length > 0)
			{
				string value2 = value.Substring(0, 2);
				value = value.Remove(0, 2);
				leBigCreateSync.UserFields.BroadcastcodeList[num2] = Convert.ToUInt32(value2, 16);
				num2++;
			}
		}
		if (index == ++num)
		{
			leBigCreateSync.UserFields.Mse = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			leBigCreateSync.UserFields.BigSyncTimeout = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			leBigCreateSync.UserFields.NumBis = Convert.ToUInt32(value, 16);
			return;
		}
		for (int i = 0; i < leBigCreateSync.UserFields.BissList.Count; i++)
		{
			if (index == ++num)
			{
				leBigCreateSync.UserFields.BissList[i].Bis = Convert.ToUInt32(value, 16);
				break;
			}
		}
	}
}
