using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class LeAdvertisingSetTerminatedInfo : PacketInfoBase
{
	public override string Name => "Le Advertising Set Terminated";

	public override string DisplayGroup => "LE Controller";

	public LeAdvertisingSetTerminatedInfo(LeAdvertisingSetTerminated packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		LeAdvertisingSetTerminated leAdvertisingSetTerminated = (LeAdvertisingSetTerminated)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Subevent_Code", "Subevent code for LE Extended Advertising Ended event", 8, FormatValue(leAdvertisingSetTerminated.UserFields.SubeventCode, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Status", ErrorCodeInfo.ErrorCodeToDescription(), 8, FormatValue(leAdvertisingSetTerminated.UserFields.Status, 8), ErrorCodeInfo.ErrorCodeToString(ErrorCodeInfo.ValueToErrorCode(leAdvertisingSetTerminated.UserFields.Status)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Advertising_Handle", "Advertising_Handle in which advertising has ended", 8, FormatValue(leAdvertisingSetTerminated.UserFields.AdvertisingHandle, 8), "", "00", "EF", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Connection_Handle", "Connection_Handle of the connection whose creation ended the advertising. Range: 0x0000-0x0EFF (0x0F00 - 0x0FFF Reserved for future use)", 16, FormatValue(leAdvertisingSetTerminated.UserFields.ConnectionHandle, 16), "", "0000", "0EFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Num_Completed_Extended_Advertising_Events", "Number of completed extended advertising events transmitted by the Controller", 8, FormatValue(leAdvertisingSetTerminated.UserFields.NumCompletedExtendedAdvertisingEvents, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

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