using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class LeChannelSelectionAlgorithmInfo : PacketInfoBase
{
	public override string Name => "Le Channel Selection Algorithm";

	public override string DisplayGroup => "LE Controller";

	public LeChannelSelectionAlgorithmInfo(LeChannelSelectionAlgorithm packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		LeChannelSelectionAlgorithm leChannelSelectionAlgorithm = (LeChannelSelectionAlgorithm)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Subevent_Code", "Subevent code for LE Channel Selection Algorithm Event", 8, FormatValue(leChannelSelectionAlgorithm.UserFields.SubeventCode, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Connection_Handle", "Connection_Handle. Range: 0x0000-0x0EFF (0x0F00 - 0x0FFF Reserved for future use)", 16, FormatValue(leChannelSelectionAlgorithm.UserFields.ConnectionHandle, 16), "", "0000", "0EFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Channel_Selection_Algorithm", LeChannelSelectionAlgorithm.UserFieldsWrapper.ChannelSelectionAlgorithmInfo.ChannelSelectionAlgorithmToDescription(), 8, FormatValue(leChannelSelectionAlgorithm.UserFields.ChannelSelectionAlgorithm, 8), LeChannelSelectionAlgorithm.UserFieldsWrapper.ChannelSelectionAlgorithmInfo.ChannelSelectionAlgorithmToString(LeChannelSelectionAlgorithm.UserFieldsWrapper.ChannelSelectionAlgorithmInfo.ValueToChannelSelectionAlgorithm(leChannelSelectionAlgorithm.UserFields.ChannelSelectionAlgorithm)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

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