using System;
using QCRPG.Framework;

namespace QCRPG.TSL.FMHCI.Packets;

public class SetBlendInfo : PacketInfoBase
{
	public override string Name => "Set Blend";

	public override string DisplayGroup => "Receiver Control";

	public SetBlendInfo(SetBlend packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		SetBlend setBlend = (SetBlend)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Type", SetBlend.UserFieldsWrapper.TypeInfo.TypeToDescription(), 8, FormatValue(setBlend.UserFields.Type, 8), SetBlend.UserFieldsWrapper.TypeInfo.TypeToString(SetBlend.UserFieldsWrapper.TypeInfo.ValueToType(setBlend.UserFields.Type)), "", "2", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Ramp Rate Up", "The ramp rate which will limit the change within index to higher index direction.\r\n0 = disable ramp rate.\r\nPositive value = Limit X index change to higher index direction.", 8, FormatValue(setBlend.UserFields.RampRateUp, 8), "", "", "31", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Debounce Number Of Samples Up", "Need to see higher or equal to the value in the index Debounce Index Up this number of times in a row before applying higher index blend value.  0 disables this feature.", 8, FormatValue(setBlend.UserFields.DebounceNumberOfSamplesUp, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Debounce Index Up", "The new blend value which shall be higher or equal to the value in the index Debounce Index Up will be updated if the previously applied blend value is lower than the value in this index.  0 disables this feature.", 8, FormatValue(setBlend.UserFields.DebounceIndexUp, 8), "", "", "31", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("SINR Index Skip Step", "The index step which will spread out SINR change slowly throughout blend table from the index Index High to the index 0 in table.  0 disables this feature.", 8, FormatValue(setBlend.UserFields.SinrIndexSkipStep, 8), "", "", "30", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("SINR High", "SINR corresponding to the last active index item of the blend table based on Index High (signed, -128 [0x80] to 127 [0x7F]).  This parameter is ignored if Type is 0x02, CONSIDER_RMSSI_ONLY.", 8, FormatValue(setBlend.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 blend table based on Index High (signed, -128 [0x80] to 127 [0x7F]).  This parameter is ignored if Type is 0x01, CONSIDER_SINR_ONLY.", 8, FormatValue(setBlend.UserFields.RmssiHigh, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Index High", "Highest index being used in the blend table.", 8, FormatValue(setBlend.UserFields.IndexHigh, 8), "", "", "31", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Blend Table", "Blend table", setBlend.UserFields.BlendTableList.Count * 8, FormatValue(setBlend.UserFields.BlendTableList, setBlend.UserFields.BlendTableList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

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