using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class HciModeChangeInfo : PacketInfoBase
{
	public override string Name => "Hci Mode Change";

	public override string DisplayGroup => "Link Policy";

	public HciModeChangeInfo(HciModeChange packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		HciModeChange hciModeChange = (HciModeChange)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Status", ErrorCodeInfo.ErrorCodeToDescription(), 8, FormatValue(hciModeChange.UserFields.Status, 8), ErrorCodeInfo.ErrorCodeToString(ErrorCodeInfo.ValueToErrorCode(hciModeChange.UserFields.Status)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Connection Handle", "Connection_Handle for which the Link Key has been changed for all devices in the same piconet.", 16, FormatValue(hciModeChange.UserFields.ConnectionHandle, 16), "", "", "0EFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Current Mode", HciModeChange.UserFieldsWrapper.CurrentModeInfo.CurrentModeToDescription(), 8, FormatValue(hciModeChange.UserFields.CurrentMode, 8), HciModeChange.UserFieldsWrapper.CurrentModeInfo.CurrentModeToString(HciModeChange.UserFieldsWrapper.CurrentModeInfo.ValueToCurrentMode(hciModeChange.UserFields.CurrentMode)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Interval", "", 16, FormatValue(hciModeChange.UserFields.Interval, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		HciModeChange hciModeChange = (HciModeChange)packet;
		int num = -1;
		if (index == ++num)
		{
			hciModeChange.UserFields.Status = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			hciModeChange.UserFields.ConnectionHandle = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			hciModeChange.UserFields.CurrentMode = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			hciModeChange.UserFields.Interval = Convert.ToUInt32(value, 16);
		}
	}
}
