using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class LeBigSyncEstablishedInfo : PacketInfoBase
{
	public override string Name => "Le Big Sync Established";

	public override string DisplayGroup => "LE Controller";

	public LeBigSyncEstablishedInfo(LeBigSyncEstablished packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		LeBigSyncEstablished leBigSyncEstablished = (LeBigSyncEstablished)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Subevent_Code", "Subevent Code for HCI_LE_BIG_Sync_Established event.", 8, FormatValue(leBigSyncEstablished.UserFields.SubeventCode, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Status", ErrorCodeInfo.ErrorCodeToDescription(), 8, FormatValue(leBigSyncEstablished.UserFields.Status, 8), ErrorCodeInfo.ErrorCodeToString(ErrorCodeInfo.ValueToErrorCode(leBigSyncEstablished.UserFields.Status)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("BIG_Handle", "Used to identify the Broadcast Isochronous Group.", 8, FormatValue(leBigSyncEstablished.UserFields.BigHandle, 8), "", "0", "EF", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Transport_Latency_BIG", "The maximum delay time, in microseconds, for transmission of SDUs of all BISes.", 24, FormatValue(leBigSyncEstablished.UserFields.TransportLatencyBig, 24), "", "0000EA", "7FFFFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("NSE", "", 8, FormatValue(leBigSyncEstablished.UserFields.Nse, 8), "", "1", "1E", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("BN", "", 8, FormatValue(leBigSyncEstablished.UserFields.Bn, 8), "", "0", "7", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("PTO", "", 8, FormatValue(leBigSyncEstablished.UserFields.Pto, 8), "", "0", "0F", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("IRC", "", 8, FormatValue(leBigSyncEstablished.UserFields.Irc, 8), "", "1", "0F", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Max_PDU", "", 16, FormatValue(leBigSyncEstablished.UserFields.MaxPdu, 16), "", "0", "FB", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("ISO_Interval", "", 16, FormatValue(leBigSyncEstablished.UserFields.IsoInterval, 16), "", "4", "0C80", 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(leBigSyncEstablished.UserFields.NumBis, 8), "", "1", "1F", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		for (int i = 0; i < leBigSyncEstablished.UserFields.ConnectionHandlesList.Count; i++)
		{
			fieldInfoList.Add(new PacketFieldInfo("Connection_Handle[" + i + "]", "List of the connection handles of the Broadcast Isochronous Streams.", 16, FormatValue(leBigSyncEstablished.UserFields.ConnectionHandlesList[i].ConnectionHandle, 16), "", "0000", "0EFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		}
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		LeBigSyncEstablished leBigSyncEstablished = (LeBigSyncEstablished)packet;
		int num = -1;
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field SubeventCode");
		}
		if (index == ++num)
		{
			leBigSyncEstablished.UserFields.Status = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			leBigSyncEstablished.UserFields.BigHandle = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			leBigSyncEstablished.UserFields.TransportLatencyBig = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			leBigSyncEstablished.UserFields.Nse = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			leBigSyncEstablished.UserFields.Bn = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			leBigSyncEstablished.UserFields.Pto = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			leBigSyncEstablished.UserFields.Irc = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			leBigSyncEstablished.UserFields.MaxPdu = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			leBigSyncEstablished.UserFields.IsoInterval = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			leBigSyncEstablished.UserFields.NumBis = Convert.ToUInt32(value, 16);
			return;
		}
		for (int i = 0; i < leBigSyncEstablished.UserFields.ConnectionHandlesList.Count; i++)
		{
			if (index == ++num)
			{
				leBigSyncEstablished.UserFields.ConnectionHandlesList[i].ConnectionHandle = Convert.ToUInt32(value, 16);
				break;
			}
		}
	}
}
