using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

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

	public override string DisplayGroup => "LE Controller";

	public LePeriodicAdvertisingSyncEstablishedInfo(LePeriodicAdvertisingSyncEstablished packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		LePeriodicAdvertisingSyncEstablished lePeriodicAdvertisingSyncEstablished = (LePeriodicAdvertisingSyncEstablished)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Subevent_Code", "Subevent code for LE Periodic Advertising Sync Established event", 8, FormatValue(lePeriodicAdvertisingSyncEstablished.UserFields.SubeventCode, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Status", ErrorCodeInfo.ErrorCodeToDescription(), 8, FormatValue(lePeriodicAdvertisingSyncEstablished.UserFields.Status, 8), ErrorCodeInfo.ErrorCodeToString(ErrorCodeInfo.ValueToErrorCode(lePeriodicAdvertisingSyncEstablished.UserFields.Status)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Sync_Handle", "Sync_Handle to be used to identify the periodic advertiser, Range: 0x0000-0x0EFF (0x0F00 - 0x0FFF Reserved for future use)", 16, FormatValue(lePeriodicAdvertisingSyncEstablished.UserFields.SyncHandle, 16), "", "0000", "0EFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Advertising_SID", AdvertisingSidInfo.AdvertisingSidToDescription(), 8, FormatValue(lePeriodicAdvertisingSyncEstablished.UserFields.AdvertisingSid, 8), AdvertisingSidInfo.AdvertisingSidToString(AdvertisingSidInfo.ValueToAdvertisingSid(lePeriodicAdvertisingSyncEstablished.UserFields.AdvertisingSid)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Advertiser_Address_Type", PeerResolvableAddressTypeInfo.PeerResolvableAddressTypeToDescription(), 8, FormatValue(lePeriodicAdvertisingSyncEstablished.UserFields.AdvertiserAddressType, 8), PeerResolvableAddressTypeInfo.PeerResolvableAddressTypeToString(PeerResolvableAddressTypeInfo.ValueToPeerResolvableAddressType(lePeriodicAdvertisingSyncEstablished.UserFields.AdvertiserAddressType)), "", "", 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(lePeriodicAdvertisingSyncEstablished.UserFields.AdvertiserAddress, 48), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Advertiser_PHY", AdvertisingPhyInfo.AdvertisingPhyToDescription(), 8, FormatValue(lePeriodicAdvertisingSyncEstablished.UserFields.AdvertiserPhy, 8), AdvertisingPhyInfo.AdvertisingPhyToString(AdvertisingPhyInfo.ValueToAdvertisingPhy(lePeriodicAdvertisingSyncEstablished.UserFields.AdvertiserPhy)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Periodic_Advertising_Interval", "Advertising interval, Range: 0x0006 to 0xFFFF, Time = N * 1.25 ms, Time Range: 7.5 ms to 81.91875 s", 16, FormatValue(lePeriodicAdvertisingSyncEstablished.UserFields.PeriodicAdvertisingInterval, 16), ValueTimes1p25MsecExpression.ValueTimes1p25MsecToString(lePeriodicAdvertisingSyncEstablished.UserFields.PeriodicAdvertisingInterval), "0006", "FFFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Advertiser_Clock_Accuracy", ClockAccuracyInfo.ClockAccuracyToDescription(), 8, FormatValue(lePeriodicAdvertisingSyncEstablished.UserFields.AdvertiserClockAccuracy, 8), ClockAccuracyInfo.ClockAccuracyToString(ClockAccuracyInfo.ValueToClockAccuracy(lePeriodicAdvertisingSyncEstablished.UserFields.AdvertiserClockAccuracy)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		LePeriodicAdvertisingSyncEstablished lePeriodicAdvertisingSyncEstablished = (LePeriodicAdvertisingSyncEstablished)packet;
		int num = -1;
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field SubeventCode");
		}
		if (index == ++num)
		{
			lePeriodicAdvertisingSyncEstablished.UserFields.Status = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			lePeriodicAdvertisingSyncEstablished.UserFields.SyncHandle = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			lePeriodicAdvertisingSyncEstablished.UserFields.AdvertisingSid = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			lePeriodicAdvertisingSyncEstablished.UserFields.AdvertiserAddressType = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			lePeriodicAdvertisingSyncEstablished.UserFields.AdvertiserAddress = Convert.ToUInt64(value, 16);
		}
		else if (index == ++num)
		{
			lePeriodicAdvertisingSyncEstablished.UserFields.AdvertiserPhy = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			lePeriodicAdvertisingSyncEstablished.UserFields.PeriodicAdvertisingInterval = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			lePeriodicAdvertisingSyncEstablished.UserFields.AdvertiserClockAccuracy = Convert.ToUInt32(value, 16);
		}
	}
}
