using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class RoleChangeInfo : PacketInfoBase
{
	public override string Name => "Role Change";

	public override string DisplayGroup => "Link Policy";

	public RoleChangeInfo(RoleChange packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		RoleChange roleChange = (RoleChange)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Status", ErrorCodeInfo.ErrorCodeToDescription(), 8, FormatValue(roleChange.UserFields.Status, 8), ErrorCodeInfo.ErrorCodeToString(ErrorCodeInfo.ValueToErrorCode(roleChange.UserFields.Status)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("BD_ADDR", "BD_ADDR of the Device for which a role change has completed", 48, FormatValue(roleChange.UserFields.BdAddr, 48), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("New_Role", RoleChange.UserFieldsWrapper.NewRoleInfo.NewRoleToDescription(), 8, FormatValue(roleChange.UserFields.NewRole, 8), RoleChange.UserFieldsWrapper.NewRoleInfo.NewRoleToString(RoleChange.UserFieldsWrapper.NewRoleInfo.ValueToNewRole(roleChange.UserFields.NewRole)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

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