using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class SetMwsPatternConfigurationInfo : PacketInfoBase
{
	public override string Name => "Set Mws Pattern Configuration";

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

	public SetMwsPatternConfigurationInfo(SetMwsPatternConfiguration packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		SetMwsPatternConfiguration setMwsPatternConfiguration = (SetMwsPatternConfiguration)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("MWS_PATTERN_Index", "Index of the MWS_PATTERN instance to be configured. Range is 0-2.", 8, FormatValue(setMwsPatternConfiguration.UserFields.MwsPatternIndex, 8), "", "00", "02", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("MWS_PATTERN_NumIntervals", "The number of intervals in the following array", 8, FormatValue(setMwsPatternConfiguration.UserFields.MwsPatternNumintervals, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		for (int i = 0; i < setMwsPatternConfiguration.UserFields.NumIntervalsList.Count; i++)
		{
			fieldInfoList.Add(new PacketFieldInfo("MWS_PATTERN_IntervalDuration[" + i + "]", "An array specifying the duration of Bluetooth activity intervals in microseconds.", 16, FormatValue(setMwsPatternConfiguration.UserFields.NumIntervalsList[i].MwsPatternIntervalduration, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("MWS_PATTERN_IntervalType[" + i + "]", "An array specifying the types of permitted Bluetooth activities in each interval: (00) Neither transmission nor reception is allowed. (01) Transmission is allowed. (02) Reception is allowed. (03) Both transmission and reception are allowed. (04) Interval for the MWS frame as defined by the Set_External_Frame_Configuration command.", 8, FormatValue(setMwsPatternConfiguration.UserFields.NumIntervalsList[i].MwsPatternIntervaltype, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		}
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		SetMwsPatternConfiguration setMwsPatternConfiguration = (SetMwsPatternConfiguration)packet;
		int num = -1;
		if (index == ++num)
		{
			setMwsPatternConfiguration.UserFields.MwsPatternIndex = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			setMwsPatternConfiguration.UserFields.MwsPatternNumintervals = Convert.ToUInt32(value, 16);
			return;
		}
		for (int i = 0; i < setMwsPatternConfiguration.UserFields.NumIntervalsList.Count; i++)
		{
			if (index == ++num)
			{
				setMwsPatternConfiguration.UserFields.NumIntervalsList[i].MwsPatternIntervalduration = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				setMwsPatternConfiguration.UserFields.NumIntervalsList[i].MwsPatternIntervaltype = Convert.ToUInt32(value, 16);
				break;
			}
		}
	}
}
