using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class LeCisEstablishedInfo : PacketInfoBase
{
	public override string Name => "Le Cis Established";

	public override string DisplayGroup => "LE Controller";

	public LeCisEstablishedInfo(LeCisEstablished packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		LeCisEstablished leCisEstablished = (LeCisEstablished)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Subevent_Code", "Subevent code for LE CIS established", 8, FormatValue(leCisEstablished.UserFields.SubeventCode, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Status", ErrorCodeInfo.ErrorCodeToDescription(), 8, FormatValue(leCisEstablished.UserFields.Status, 8), ErrorCodeInfo.ErrorCodeToString(ErrorCodeInfo.ValueToErrorCode(leCisEstablished.UserFields.Status)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Connection_Handle", "Connection handle of the Connected Isochronous Stream.", 16, FormatValue(leCisEstablished.UserFields.ConnectionHandle, 16), "", "0000", "0EFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("CIG_Sync_Delay", "The CIG synchronization delay time in microseconds.", 24, FormatValue(leCisEstablished.UserFields.CigSyncDelay, 24), "", "EA", "7FFFFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("CIS_Sync_Delay", "The CIS synchronization delay time in microseconds.", 24, FormatValue(leCisEstablished.UserFields.CisSyncDelay, 24), "", "EA", "7FFFFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Transport_Latency_M_To_S", "The maximum time, in microseconds, for transmission of SDUs of all CISes from master to slave.", 24, FormatValue(leCisEstablished.UserFields.TransportLatencyMToS, 24), "", "EA", "7FFFFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Transport_Latency_S_To_M", "The maximum time, in microseconds, for transmission of SDUs of all CISes from slave to master.", 24, FormatValue(leCisEstablished.UserFields.TransportLatencySToM, 24), "", "EA", "7FFFFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("PHY_M_TO_S", LePhyInfo.LePhyToDescription(), 8, FormatValue(leCisEstablished.UserFields.PhyMToS, 8), LePhyInfo.LePhyToString(LePhyInfo.ValueToLePhy(leCisEstablished.UserFields.PhyMToS)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("PHY_S_TO_M", LePhyInfo.LePhyToDescription(), 8, FormatValue(leCisEstablished.UserFields.PhySToM, 8), LePhyInfo.LePhyToString(LePhyInfo.ValueToLePhy(leCisEstablished.UserFields.PhySToM)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("NSE", "", 8, FormatValue(leCisEstablished.UserFields.Nse, 8), "", "1", "1E", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("BN_M_TO_S", "", 8, FormatValue(leCisEstablished.UserFields.BnMToS, 8), "", "0", "0F", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("BN_S_TO_M", "", 8, FormatValue(leCisEstablished.UserFields.BnSToM, 8), "", "0", "0F", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("FT_M_TO_S", "", 8, FormatValue(leCisEstablished.UserFields.FtMToS, 8), "", "1", "FF", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("FT_S_TO_M", "", 8, FormatValue(leCisEstablished.UserFields.FtSToM, 8), "", "1", "FF", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Max_PDU_M_TO_S", "", 16, FormatValue(leCisEstablished.UserFields.MaxPduMToS, 16), "", "0", "FB", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Max_PDU_S_TO_M", "", 16, FormatValue(leCisEstablished.UserFields.MaxPduSToM, 16), "", "0", "FB", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("ISO_Interval", "", 16, FormatValue(leCisEstablished.UserFields.IsoInterval, 16), "", "4", "0C80", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		LeCisEstablished leCisEstablished = (LeCisEstablished)packet;
		int num = -1;
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field SubeventCode");
		}
		if (index == ++num)
		{
			leCisEstablished.UserFields.Status = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leCisEstablished.UserFields.ConnectionHandle = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leCisEstablished.UserFields.CigSyncDelay = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leCisEstablished.UserFields.CisSyncDelay = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leCisEstablished.UserFields.TransportLatencyMToS = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leCisEstablished.UserFields.TransportLatencySToM = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leCisEstablished.UserFields.PhyMToS = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leCisEstablished.UserFields.PhySToM = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leCisEstablished.UserFields.Nse = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leCisEstablished.UserFields.BnMToS = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leCisEstablished.UserFields.BnSToM = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leCisEstablished.UserFields.FtMToS = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leCisEstablished.UserFields.FtSToM = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leCisEstablished.UserFields.MaxPduMToS = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leCisEstablished.UserFields.MaxPduSToM = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leCisEstablished.UserFields.IsoInterval = Convert.ToUInt32(value, 16);
		}
	}
}
