using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class LeMultiAdvtStateChangeInfo : PacketInfoBase
{
	public override string Name => "Le Multi Advt State Change";

	public override string DisplayGroup => "Vendor Specific";

	public LeMultiAdvtStateChangeInfo(LeMultiAdvtStateChange packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		LeMultiAdvtStateChange leMultiAdvtStateChange = (LeMultiAdvtStateChange)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("sub_event_code", "LE Multi Advt State change", 8, FormatValue(leMultiAdvtStateChange.UserFields.SubEventCode, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Advertising_Instance", "Identifies the specific advertising instance. Valid values 0 through (max_advt_instances - 1)", 8, FormatValue(leMultiAdvtStateChange.UserFields.AdvertisingInstance, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("State_change_Reason", LeMultiAdvtStateChange.UserFieldsWrapper.StateChangeReasonInfo.StateChangeReasonToDescription(), 8, FormatValue(leMultiAdvtStateChange.UserFields.StateChangeReason, 8), LeMultiAdvtStateChange.UserFieldsWrapper.StateChangeReasonInfo.StateChangeReasonToString(LeMultiAdvtStateChange.UserFieldsWrapper.StateChangeReasonInfo.ValueToStateChangeReason(leMultiAdvtStateChange.UserFields.StateChangeReason)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Connection_handle", "Identifies the connection that caused the advt instance to be disabled(0xFFFF if invalid)", 16, FormatValue(leMultiAdvtStateChange.UserFields.ConnectionHandle, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

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