using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class WriteSynchronizationTrainParametersInfo : PacketInfoBase
{
	public override string Name => "Write Synchronization Train Parameters";

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

	public WriteSynchronizationTrainParametersInfo(WriteSynchronizationTrainParameters packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		WriteSynchronizationTrainParameters writeSynchronizationTrainParameters = (WriteSynchronizationTrainParameters)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Interval_Min", "Minimum value allowed for the interval Sync_Train_Interval in slots. Range: 0x0020-0xFFFE; only even values are valid", 16, FormatValue(writeSynchronizationTrainParameters.UserFields.IntervalMin, 16), "", "0020", "FFFE", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Interval_Max", "Maximum value allowed for the interval Sync_Train_Interval in slots. Range: 0x0020-0xFFFE; only even values are valid", 16, FormatValue(writeSynchronizationTrainParameters.UserFields.IntervalMax, 16), "", "0020", "FFFE", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("synchronization_trainTO", "Duration in slots to continue sending the synchronization train. Range: 0x00000002 - 0x07FFFFFE; only even values are valid", 32, FormatValue(writeSynchronizationTrainParameters.UserFields.SynchronizationTrainto, 32), "", "00000002", "07FFFFFE", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Service_Data", "Host provided value to be included in octet 27 of the Synchronization Train packet payload body; see BT Specification (Synchronization Train Substate section, Table: Synchronization Train Packet Payload Body).", 8, FormatValue(writeSynchronizationTrainParameters.UserFields.ServiceData, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		WriteSynchronizationTrainParameters writeSynchronizationTrainParameters = (WriteSynchronizationTrainParameters)packet;
		int num = -1;
		if (index == ++num)
		{
			writeSynchronizationTrainParameters.UserFields.IntervalMin = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			writeSynchronizationTrainParameters.UserFields.IntervalMax = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			writeSynchronizationTrainParameters.UserFields.SynchronizationTrainto = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			writeSynchronizationTrainParameters.UserFields.ServiceData = Convert.ToUInt32(value, 16);
		}
	}
}
