using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class LeCisRequestInfo : PacketInfoBase
{
	public override string Name => "Le Cis Request";

	public override string DisplayGroup => "LE Controller";

	public LeCisRequestInfo(LeCisRequest packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		LeCisRequest leCisRequest = (LeCisRequest)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Subevent_Code", "Subevent code for LE CIS Request.", 8, FormatValue(leCisRequest.UserFields.SubeventCode, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("ACL_Connection_Handle", "Connection handle of the ACL.", 16, FormatValue(leCisRequest.UserFields.AclConnectionHandle, 16), "", "0000", "0EFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("CIS_Connection_Handle", "Connection handle of the  Connected Isochronous Stream.", 16, FormatValue(leCisRequest.UserFields.CisConnectionHandle, 16), "", "0000", "0EFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("CIG_ID", "Identifier of the Connected Isochronous Stream Group.", 8, FormatValue(leCisRequest.UserFields.CigId, 8), "", "0", "EF", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("CIS_ID", "Identifier of the Connected Isochronous Stream.", 8, FormatValue(leCisRequest.UserFields.CisId, 8), "", "0", "EF", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		LeCisRequest leCisRequest = (LeCisRequest)packet;
		int num = -1;
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field SubeventCode");
		}
		if (index == ++num)
		{
			leCisRequest.UserFields.AclConnectionHandle = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leCisRequest.UserFields.CisConnectionHandle = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leCisRequest.UserFields.CigId = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leCisRequest.UserFields.CisId = Convert.ToUInt32(value, 16);
		}
	}
}
