using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class SwitchRoleInfo : PacketInfoBase
{
	public override string Name => "Switch Role";

	public override string DisplayGroup => "Link Policy";

	public SwitchRoleInfo(SwitchRole packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		SwitchRole switchRole = (SwitchRole)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("BD_ADDR", "BD_ADDR for the connected device with which a role switch is to be performed", 48, FormatValue(switchRole.UserFields.BdAddr, 48), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Role", SwitchRole.UserFieldsWrapper.RoleInfo.RoleToDescription(), 8, FormatValue(switchRole.UserFields.Role, 8), SwitchRole.UserFieldsWrapper.RoleInfo.RoleToString(SwitchRole.UserFieldsWrapper.RoleInfo.ValueToRole(switchRole.UserFields.Role)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		SwitchRole switchRole = (SwitchRole)packet;
		int num = -1;
		if (index == ++num)
		{
			switchRole.UserFields.BdAddr = Convert.ToUInt64(value, 16);
		}
		else if (index == ++num)
		{
			switchRole.UserFields.Role = Convert.ToUInt32(value, 16);
		}
	}
}
