using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class LePeriodicAdvertisingCreateSyncInfo : PacketInfoBase
{
	public override string Name => "Le Periodic Advertising Create Sync";

	public override string DisplayGroup => "LE Controller";

	public LePeriodicAdvertisingCreateSyncInfo(LePeriodicAdvertisingCreateSync packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		LePeriodicAdvertisingCreateSync lePeriodicAdvertisingCreateSync = (LePeriodicAdvertisingCreateSync)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Option", LePeriodicAdvertisingCreateSync.UserFieldsWrapper.OptionInfo.OptionToDescription(), 8, FormatValue(lePeriodicAdvertisingCreateSync.UserFields.Option, 8), LePeriodicAdvertisingCreateSync.UserFieldsWrapper.OptionInfo.OptionToString(LePeriodicAdvertisingCreateSync.UserFieldsWrapper.OptionInfo.ValueToOption(lePeriodicAdvertisingCreateSync.UserFields.Option)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Advertising_SID", "Advertising SID subfield in the ADI field used to identify the Periodic Advertising", 8, FormatValue(lePeriodicAdvertisingCreateSync.UserFields.AdvertisingSid, 8), "", "00", "0F", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Advertising_Address_Type", DeviceAddressTypeInfo.DeviceAddressTypeToDescription(), 8, FormatValue(lePeriodicAdvertisingCreateSync.UserFields.AdvertisingAddressType, 8), DeviceAddressTypeInfo.DeviceAddressTypeToString(DeviceAddressTypeInfo.ValueToDeviceAddressType(lePeriodicAdvertisingCreateSync.UserFields.AdvertisingAddressType)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Advertiser_Address", "Public Device Address, Random Device Address, Public Identity Address, or Random (static) Identity Address of the advertiser.", 48, FormatValue(lePeriodicAdvertisingCreateSync.UserFields.AdvertiserAddress, 48), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Skip", "The number of periodic advertising events that can be skipped after a successful receive", 16, FormatValue(lePeriodicAdvertisingCreateSync.UserFields.Skip, 16), "", "0000", "01F3", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Sync_Timeout", "Synchronization timeout for the periodic advertising. Range: 0x000A to 0x4000, Time = N*10 ms, Time Range: 100 ms to 163.84 s\r\n\r\n" + SupervisionTimeoutInfo.SupervisionTimeoutToDescription(), 16, FormatValue(lePeriodicAdvertisingCreateSync.UserFields.SyncTimeout, 16), SupervisionTimeoutInfo.SupervisionTimeoutToString(SupervisionTimeoutInfo.ValueToSupervisionTimeout(lePeriodicAdvertisingCreateSync.UserFields.SyncTimeout)), "000A", "4000", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Supplemental_Type", LePeriodicAdvertisingCreateSync.UserFieldsWrapper.SupplementalTypeInfo.SupplementalTypeToDescription(), 8, FormatValue(lePeriodicAdvertisingCreateSync.UserFields.SupplementalType, 8), LePeriodicAdvertisingCreateSync.UserFieldsWrapper.SupplementalTypeInfo.SupplementalTypeToString(LePeriodicAdvertisingCreateSync.UserFieldsWrapper.SupplementalTypeInfo.ValueToSupplementalType(lePeriodicAdvertisingCreateSync.UserFields.SupplementalType)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		LePeriodicAdvertisingCreateSync lePeriodicAdvertisingCreateSync = (LePeriodicAdvertisingCreateSync)packet;
		int num = -1;
		if (index == ++num)
		{
			lePeriodicAdvertisingCreateSync.UserFields.Option = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			lePeriodicAdvertisingCreateSync.UserFields.AdvertisingSid = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			lePeriodicAdvertisingCreateSync.UserFields.AdvertisingAddressType = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			lePeriodicAdvertisingCreateSync.UserFields.AdvertiserAddress = Convert.ToUInt64(value, 16);
		}
		else if (index == ++num)
		{
			lePeriodicAdvertisingCreateSync.UserFields.Skip = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			lePeriodicAdvertisingCreateSync.UserFields.SyncTimeout = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			lePeriodicAdvertisingCreateSync.UserFields.SupplementalType = Convert.ToUInt32(value, 16);
		}
	}
}
