using System;
using QCRPG.Framework;

namespace QCRPG.TSL.FMHCI.Packets;

public class SetSoftMuteInfo : PacketInfoBase
{
	public override string Name => "Set Soft Mute";

	public override string DisplayGroup => "Receiver Control";

	public SetSoftMuteInfo(SetSoftMute packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		SetSoftMute setSoftMute = (SetSoftMute)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Type", SetSoftMute.UserFieldsWrapper.TypeInfo.TypeToDescription(), 8, FormatValue(setSoftMute.UserFields.Type, 8), SetSoftMute.UserFieldsWrapper.TypeInfo.TypeToString(SetSoftMute.UserFieldsWrapper.TypeInfo.ValueToType(setSoftMute.UserFields.Type)), "", "1", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Ramp Rate", "Signed value.\r\n0 = disable ramp rate.\r\nNegative value = wait based on the RX channel condition tiemr X time(s) and limit 1 index change.\r\nPositive value = Limit X index change.", 8, FormatValue(setSoftMute.UserFields.RampRate, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("SINR High", "SINR corresponding to the last active index item of the soft mute table based on Mute Index High (signed, -128 [0x80] to 127 [0x7F])", 8, FormatValue(setSoftMute.UserFields.SinrHigh, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("RMSSI High", "RMSSI corresponding to the last active index item of the soft mute table based on Mute Index High (signed, -128 [0x80] to 127 [0x7F]); ignored if Mute Type is 0x00", 8, FormatValue(setSoftMute.UserFields.RmssiHigh, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Index High", "Highest index being used in soft mute table", 8, FormatValue(setSoftMute.UserFields.IndexHigh, 8), "", "", "31", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Soft Mute Table", "Soft mute table", setSoftMute.UserFields.SoftMuteTableList.Count * 8, FormatValue(setSoftMute.UserFields.SoftMuteTableList, setSoftMute.UserFields.SoftMuteTableList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		SetSoftMute setSoftMute = (SetSoftMute)packet;
		int num = -1;
		if (index == ++num)
		{
			setSoftMute.UserFields.Type = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			setSoftMute.UserFields.RampRate = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			setSoftMute.UserFields.SinrHigh = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			setSoftMute.UserFields.RmssiHigh = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			setSoftMute.UserFields.IndexHigh = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			value = AddLeadingZerosAndCheckValueStringLength(value, setSoftMute.UserFields.SoftMuteTableList.Count);
			int num2 = 0;
			while (value.Length > 0)
			{
				string value2 = value.Substring(0, 2);
				value = value.Remove(0, 2);
				setSoftMute.UserFields.SoftMuteTableList[num2] = Convert.ToUInt32(value2, 16);
				num2++;
			}
		}
	}
}
