using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class LeSupplementalRequestFailedInfo : PacketInfoBase
{
	public override string Name => "Le Supplemental Request Failed";

	public override string DisplayGroup => "LE Controller";

	public LeSupplementalRequestFailedInfo(LeSupplementalRequestFailed packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		LeSupplementalRequestFailed leSupplementalRequestFailed = (LeSupplementalRequestFailed)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Subevent code", "", 8, FormatValue(leSupplementalRequestFailed.UserFields.SubeventCode, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Status", ErrorCodeInfo.ErrorCodeToDescription(), 8, FormatValue(leSupplementalRequestFailed.UserFields.Status, 8), ErrorCodeInfo.ErrorCodeToString(ErrorCodeInfo.ValueToErrorCode(leSupplementalRequestFailed.UserFields.Status)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Connection_Handle", "", 16, FormatValue(leSupplementalRequestFailed.UserFields.ConnectionHandle, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

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