using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class LeCreateCisInfo : PacketInfoBase
{
	public override string Name => "Le Create Cis";

	public override string DisplayGroup => "LE Controller";

	public LeCreateCisInfo(LeCreateCis packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		LeCreateCis leCreateCis = (LeCreateCis)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("CIS_Count", "Total number of CISes.", 8, FormatValue(leCreateCis.UserFields.CisCount, 8), "", "1", "1F", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		for (int i = 0; i < leCreateCis.UserFields.ConnectionHandlesList.Count; i++)
		{
			fieldInfoList.Add(new PacketFieldInfo("CIS_Connection_Handle[" + i + "]", "Connection handle of the CIS.", 16, FormatValue(leCreateCis.UserFields.ConnectionHandlesList[i].CisConnectionHandle, 16), "", "0000", "0EFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("ACL_Connection_Handle[" + i + "]", "Connection handle of the ACL.", 16, FormatValue(leCreateCis.UserFields.ConnectionHandlesList[i].AclConnectionHandle, 16), "", "0000", "0EFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		}
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		LeCreateCis leCreateCis = (LeCreateCis)packet;
		int num = -1;
		if (index == ++num)
		{
			leCreateCis.UserFields.CisCount = Convert.ToUInt32(value, 16);
			return;
		}
		for (int i = 0; i < leCreateCis.UserFields.ConnectionHandlesList.Count; i++)
		{
			if (index == ++num)
			{
				leCreateCis.UserFields.ConnectionHandlesList[i].CisConnectionHandle = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				leCreateCis.UserFields.ConnectionHandlesList[i].AclConnectionHandle = Convert.ToUInt32(value, 16);
				break;
			}
		}
	}
}
