using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class LeApcfBroadcastAddressInfo : PacketInfoBase
{
	public override string Name => "Le Apcf Broadcast Address";

	public override string DisplayGroup => "Vendor Specific";

	public LeApcfBroadcastAddressInfo(LeApcfBroadcastAddress packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		LeApcfBroadcastAddress leApcfBroadcastAddress = (LeApcfBroadcastAddress)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("APCF_opcode", "APCF Broadcaster Address", 8, FormatValue(leApcfBroadcastAddress.UserFields.ApcfOpcode, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("APCF_Action", LeApcfBroadcastAddress.UserFieldsWrapper.ApcfActionInfo.ApcfActionToDescription(), 8, FormatValue(leApcfBroadcastAddress.UserFields.ApcfAction, 8), LeApcfBroadcastAddress.UserFieldsWrapper.ApcfActionInfo.ApcfActionToString(LeApcfBroadcastAddress.UserFieldsWrapper.ApcfActionInfo.ValueToApcfAction(leApcfBroadcastAddress.UserFields.ApcfAction)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("APCF_Filter_Index", "Filter index (0, max_filter-1)", 8, FormatValue(leApcfBroadcastAddress.UserFields.ApcfFilterIndex, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("APCF_Broadcaster_Address", "6-byte device address to add to or delete from the broadcaster address list", 48, FormatValue(leApcfBroadcastAddress.UserFields.ApcfBroadcasterAddress, 48), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("APCF_Application_Address_type", LeApcfBroadcastAddress.UserFieldsWrapper.ApcfApplicationAddressTypeInfo.ApcfApplicationAddressTypeToDescription(), 8, FormatValue(leApcfBroadcastAddress.UserFields.ApcfApplicationAddressType, 8), LeApcfBroadcastAddress.UserFieldsWrapper.ApcfApplicationAddressTypeInfo.ApcfApplicationAddressTypeToString(LeApcfBroadcastAddress.UserFieldsWrapper.ApcfApplicationAddressTypeInfo.ValueToApcfApplicationAddressType(leApcfBroadcastAddress.UserFields.ApcfApplicationAddressType)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		LeApcfBroadcastAddress leApcfBroadcastAddress = (LeApcfBroadcastAddress)packet;
		int num = -1;
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field ApcfOpcode");
		}
		if (index == ++num)
		{
			leApcfBroadcastAddress.UserFields.ApcfAction = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leApcfBroadcastAddress.UserFields.ApcfFilterIndex = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leApcfBroadcastAddress.UserFields.ApcfBroadcasterAddress = Convert.ToUInt64(value, 16);
		}
		else if (index == ++num)
		{
			leApcfBroadcastAddress.UserFields.ApcfApplicationAddressType = Convert.ToUInt32(value, 16);
		}
	}
}
