using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class QcmPhyChangedInfo : PacketInfoBase
{
	public override string Name => "Qcm Phy Changed";

	public override string DisplayGroup => "Vendor Specific";

	public QcmPhyChangedInfo(QcmPhyChanged packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		QcmPhyChanged qcmPhyChanged = (QcmPhyChanged)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Subevent_Code", "Subevent code for QBCE VS events", 8, FormatValue(qcmPhyChanged.UserFields.SubeventCode, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Message Type", "QCM_PHY_Changed", 8, FormatValue(qcmPhyChanged.UserFields.MessageType, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Status", ErrorCodeInfo.ErrorCodeToDescription(), 8, FormatValue(qcmPhyChanged.UserFields.Status, 8), ErrorCodeInfo.ErrorCodeToString(ErrorCodeInfo.ValueToErrorCode(qcmPhyChanged.UserFields.Status)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Connection_Handle", "The Connection_Handle for the Connection for which the LE_Read_PHY is to to be read. Range:0x0000-0x0EFF (0x0F00 - 0x0FFF Reserved for future use)", 16, FormatValue(qcmPhyChanged.UserFields.ConnectionHandle, 16), "", "0000", "0EFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("PHY", QcmPhyChanged.UserFieldsWrapper.PhyInfo.PhyToDescription(), 8, FormatValue(qcmPhyChanged.UserFields.Phy, 8), QcmPhyChanged.UserFieldsWrapper.PhyInfo.PhyToString(QcmPhyChanged.UserFieldsWrapper.PhyInfo.ValueToPhy(qcmPhyChanged.UserFields.Phy)), "0", "1", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Source", QcmPhyChanged.UserFieldsWrapper.SourceInfo.SourceToDescription(), 8, FormatValue(qcmPhyChanged.UserFields.Source, 8), QcmPhyChanged.UserFieldsWrapper.SourceInfo.SourceToString(QcmPhyChanged.UserFieldsWrapper.SourceInfo.ValueToSource(qcmPhyChanged.UserFields.Source)), "0", "1", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		QcmPhyChanged qcmPhyChanged = (QcmPhyChanged)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)
		{
			qcmPhyChanged.UserFields.Status = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			qcmPhyChanged.UserFields.ConnectionHandle = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			qcmPhyChanged.UserFields.Phy = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			qcmPhyChanged.UserFields.Source = Convert.ToUInt32(value, 16);
		}
	}
}
