using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class WriteLocationDataInfo : PacketInfoBase
{
	public override string Name => "Write Location Data";

	public override string DisplayGroup => "Host Control and Baseband";

	public WriteLocationDataInfo(WriteLocationData packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		WriteLocationData writeLocationData = (WriteLocationData)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Location_Domain_Aware", WriteLocationData.UserFieldsWrapper.LocationDomainAwareInfo.LocationDomainAwareToDescription(), 8, FormatValue(writeLocationData.UserFields.LocationDomainAware, 8), WriteLocationData.UserFieldsWrapper.LocationDomainAwareInfo.LocationDomainAwareToString(WriteLocationData.UserFieldsWrapper.LocationDomainAwareInfo.ValueToLocationDomainAware(writeLocationData.UserFields.LocationDomainAware)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Location_Domain", "Shall be set to the character string 'X' (0x5858) for a non-country entity or when Location_Domain_Aware is set to regulatory domain unknown. When the regulatory domain is known, it shall be set according to the two Octet country code as defined in ISO 3166-1", 16, FormatValue(writeLocationData.UserFields.LocationDomain, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Location_Domain_Options", WriteLocationData.UserFieldsWrapper.LocationDomainOptionsInfo.LocationDomainOptionsToDescription(), 8, FormatValue(writeLocationData.UserFields.LocationDomainOptions, 8), WriteLocationData.UserFieldsWrapper.LocationDomainOptionsInfo.LocationDomainOptionsToString(WriteLocationData.UserFieldsWrapper.LocationDomainOptionsInfo.ValueToLocationDomainOptions(writeLocationData.UserFields.LocationDomainOptions)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Location_Options", "Bit 0 = 0: Not mains-powered, Bit 0 = 1: Mains Powered, Bit 1-7: Reserved for future use", 8, FormatValue(writeLocationData.UserFields.LocationOptions, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		WriteLocationData writeLocationData = (WriteLocationData)packet;
		int num = -1;
		if (index == ++num)
		{
			writeLocationData.UserFields.LocationDomainAware = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			writeLocationData.UserFields.LocationDomain = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			writeLocationData.UserFields.LocationDomainOptions = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			writeLocationData.UserFields.LocationOptions = Convert.ToUInt32(value, 16);
		}
	}
}
