using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class QbceQleCisEstablishedInfo : PacketInfoBase
{
	public override string Name => "Qbce Qle Cis Established";

	public override string DisplayGroup => "Vendor Specific";

	public QbceQleCisEstablishedInfo(QbceQleCisEstablished packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		QbceQleCisEstablished qbceQleCisEstablished = (QbceQleCisEstablished)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Subevent_Code", "Subevent code for QBCE VS events", 8, FormatValue(qbceQleCisEstablished.UserFields.SubeventCode, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Message Type", "QLE_CIS_Established Event", 8, FormatValue(qbceQleCisEstablished.UserFields.MessageType, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Status", ErrorCodeInfo.ErrorCodeToDescription(), 8, FormatValue(qbceQleCisEstablished.UserFields.Status, 8), ErrorCodeInfo.ErrorCodeToString(ErrorCodeInfo.ValueToErrorCode(qbceQleCisEstablished.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(qbceQleCisEstablished.UserFields.ConnectionHandle, 16), "", "0000", "0EFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("CIG_Synchronization_Delay", "The CIG synchronization delay time in microseconds.", 24, FormatValue(qbceQleCisEstablished.UserFields.CigSynchronizationDelay, 24), "", "EA", "7FFFFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("CIS_Synchronization_Delay", "The CIS synchronization delay time in microseconds.", 24, FormatValue(qbceQleCisEstablished.UserFields.CisSynchronizationDelay, 24), "", "EA", "7FFFFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Transport_Lantency", "The CIS transport lantency in microseconds.", 24, FormatValue(qbceQleCisEstablished.UserFields.TransportLantency, 24), "", "EA", "7FFFFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("PHY_M_TO_S", QbceReceiverPhyPreferenceInfo.QbceReceiverPhyPreferenceToDescription(), 8, FormatValue(qbceQleCisEstablished.UserFields.PhyMToS, 8), QbceReceiverPhyPreferenceInfo.QbceReceiverPhyPreferenceToString(QbceReceiverPhyPreferenceInfo.ValueToQbceReceiverPhyPreference(qbceQleCisEstablished.UserFields.PhyMToS)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("PHY_S_TO_M", QbceTransmitterPhyPreferenceInfo.QbceTransmitterPhyPreferenceToDescription(), 8, FormatValue(qbceQleCisEstablished.UserFields.PhySToM, 8), QbceTransmitterPhyPreferenceInfo.QbceTransmitterPhyPreferenceToString(QbceTransmitterPhyPreferenceInfo.ValueToQbceTransmitterPhyPreference(qbceQleCisEstablished.UserFields.PhySToM)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		QbceQleCisEstablished qbceQleCisEstablished = (QbceQleCisEstablished)packet;
		int num = -1;
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field SubeventCode");
		}
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field MessageType");
		}
		if (index == ++num)
		{
			qbceQleCisEstablished.UserFields.Status = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			qbceQleCisEstablished.UserFields.ConnectionHandle = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			qbceQleCisEstablished.UserFields.CigSynchronizationDelay = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			qbceQleCisEstablished.UserFields.CisSynchronizationDelay = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			qbceQleCisEstablished.UserFields.TransportLantency = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			qbceQleCisEstablished.UserFields.PhyMToS = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			qbceQleCisEstablished.UserFields.PhySToM = Convert.ToUInt32(value, 16);
		}
	}
}
