using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class LePhyUpdateCompleteInfo : PacketInfoBase
{
	public override string Name => "Le Phy Update Complete";

	public override string DisplayGroup => "LE Controller";

	public LePhyUpdateCompleteInfo(LePhyUpdateComplete packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		LePhyUpdateComplete lePhyUpdateComplete = (LePhyUpdateComplete)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Subevent_Code", "Subevent code for LE PHY Update Complete Event", 8, FormatValue(lePhyUpdateComplete.UserFields.SubeventCode, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Status", ErrorCodeInfo.ErrorCodeToDescription(), 8, FormatValue(lePhyUpdateComplete.UserFields.Status, 8), ErrorCodeInfo.ErrorCodeToString(ErrorCodeInfo.ValueToErrorCode(lePhyUpdateComplete.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(lePhyUpdateComplete.UserFields.ConnectionHandle, 16), "", "0000", "0EFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("TX_PHY", LePhyInfo.LePhyToDescription(), 8, FormatValue(lePhyUpdateComplete.UserFields.TxPhy, 8), LePhyInfo.LePhyToString(LePhyInfo.ValueToLePhy(lePhyUpdateComplete.UserFields.TxPhy)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("RX_PHY", LePhyInfo.LePhyToDescription(), 8, FormatValue(lePhyUpdateComplete.UserFields.RxPhy, 8), LePhyInfo.LePhyToString(LePhyInfo.ValueToLePhy(lePhyUpdateComplete.UserFields.RxPhy)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		LePhyUpdateComplete lePhyUpdateComplete = (LePhyUpdateComplete)packet;
		int num = -1;
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field SubeventCode");
		}
		if (index == ++num)
		{
			lePhyUpdateComplete.UserFields.Status = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			lePhyUpdateComplete.UserFields.ConnectionHandle = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			lePhyUpdateComplete.UserFields.TxPhy = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			lePhyUpdateComplete.UserFields.RxPhy = Convert.ToUInt32(value, 16);
		}
	}
}
