using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class ParkStateInfo : PacketInfoBase
{
	public override string Name => "Park State";

	public override string DisplayGroup => "Link Policy";

	public ParkStateInfo(ParkState packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		ParkState parkState = (ParkState)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Connection_Handle", "Connection_Handle to be used to identify a connection. Range: 0x0000-0x0EFF (0x0F00 - 0x0FFF Reserved for future use)", 16, FormatValue(parkState.UserFields.ConnectionHandle, 16), "", "0000", "0EFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Beacon_Max_Interval", "Range: 0x000E to 0xFFFE; only even values are valid, Mandatory Range: 0x000E to 0x1000, Time = N * 0.625 msec, Time Range: 8.75 msec to 40.9 sec", 16, FormatValue(parkState.UserFields.BeaconMaxInterval, 16), "", "000E", "FFFE", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Beacon_Min_Interval", "Range: 0x000E to 0xFFFE; only even values are valid, Mandatory Range: 0x000E to 0x1000, Time = N * 0.625 msec, Time Range: 8.75 msec to 40.9 sec", 16, FormatValue(parkState.UserFields.BeaconMinInterval, 16), "", "000E", "FFFE", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		ParkState parkState = (ParkState)packet;
		int num = -1;
		if (index == ++num)
		{
			parkState.UserFields.ConnectionHandle = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			parkState.UserFields.BeaconMaxInterval = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			parkState.UserFields.BeaconMinInterval = Convert.ToUInt32(value, 16);
		}
	}
}
