using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class CommandCompleteForReadSynchronizationTrainParametersInfo : PacketInfoBase
{
	public override string Name => "Command Complete For Read Synchronization Train Parameters";

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

	public CommandCompleteForReadSynchronizationTrainParametersInfo(CommandCompleteForReadSynchronizationTrainParameters packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		CommandCompleteForReadSynchronizationTrainParameters commandCompleteForReadSynchronizationTrainParameters = (CommandCompleteForReadSynchronizationTrainParameters)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Num HCI Command Packets", "", 8, FormatValue(commandCompleteForReadSynchronizationTrainParameters.UserFields.NumHciCommandPackets, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Command OpCode", CommandOpcodeInfo.CommandOpcodeToDescription(), 16, FormatValue(commandCompleteForReadSynchronizationTrainParameters.UserFields.CommandOpcode, 16), CommandOpcodeInfo.CommandOpcodeToString(CommandOpcodeInfo.ValueToCommandOpcode(commandCompleteForReadSynchronizationTrainParameters.UserFields.CommandOpcode)), "", "", settable: false, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Status", ErrorCodeInfo.ErrorCodeToDescription(), 8, FormatValue(commandCompleteForReadSynchronizationTrainParameters.UserFields.Status, 8), ErrorCodeInfo.ErrorCodeToString(ErrorCodeInfo.ValueToErrorCode(commandCompleteForReadSynchronizationTrainParameters.UserFields.Status)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Sync_Train_Interval", "Interval in slots between consecutive Synchronization Train events on the same channel. Range: 0x0020-0xFFFE; only even values are valid", 16, FormatValue(commandCompleteForReadSynchronizationTrainParameters.UserFields.SyncTrainInterval, 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(commandCompleteForReadSynchronizationTrainParameters.UserFields.SynchronizationTrainto, 32), "", "00000002", "07FFFFFE", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Service_Data", "Host provided value included in Synchronization Train packet, octet 27; see BT Specification (Synchronization Train Substate section, Table: Synchronization Train Packet Payload Body).", 8, FormatValue(commandCompleteForReadSynchronizationTrainParameters.UserFields.ServiceData, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		CommandCompleteForReadSynchronizationTrainParameters commandCompleteForReadSynchronizationTrainParameters = (CommandCompleteForReadSynchronizationTrainParameters)packet;
		int num = -1;
		if (index == ++num)
		{
			commandCompleteForReadSynchronizationTrainParameters.UserFields.NumHciCommandPackets = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field CommandOpcode");
		}
		if (index == ++num)
		{
			commandCompleteForReadSynchronizationTrainParameters.UserFields.Status = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			commandCompleteForReadSynchronizationTrainParameters.UserFields.SyncTrainInterval = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			commandCompleteForReadSynchronizationTrainParameters.UserFields.SynchronizationTrainto = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			commandCompleteForReadSynchronizationTrainParameters.UserFields.ServiceData = Convert.ToUInt32(value, 16);
		}
	}
}
