using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class SetEventFilterConnectionSetupInfo : PacketInfoBase
{
	public override string Name => "Set Event Filter Connection Setup";

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

	public SetEventFilterConnectionSetupInfo(SetEventFilterConnectionSetup packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		SetEventFilterConnectionSetup setEventFilterConnectionSetup = (SetEventFilterConnectionSetup)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Filter Type", "", 8, FormatValue(setEventFilterConnectionSetup.UserFields.FilterType, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Condition Type", FilterConditionTypeInfo.FilterConditionTypeToDescription(), 8, FormatValue(setEventFilterConnectionSetup.UserFields.ConditionType, 8), FilterConditionTypeInfo.FilterConditionTypeToString(FilterConditionTypeInfo.ValueToFilterConditionType(setEventFilterConnectionSetup.UserFields.ConditionType)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Condition", "", setEventFilterConnectionSetup.UserFields.ConditionList.Count * 8, FormatValue(setEventFilterConnectionSetup.UserFields.ConditionList, setEventFilterConnectionSetup.UserFields.ConditionList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		SetEventFilterConnectionSetup setEventFilterConnectionSetup = (SetEventFilterConnectionSetup)packet;
		int num = -1;
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field FilterType");
		}
		if (index == ++num)
		{
			setEventFilterConnectionSetup.UserFields.ConditionType = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			value = AddLeadingZerosAndCheckValueStringLength(value, setEventFilterConnectionSetup.UserFields.ConditionList.Count);
			int num2 = 0;
			while (value.Length > 0)
			{
				string value2 = value.Substring(0, 2);
				value = value.Remove(0, 2);
				setEventFilterConnectionSetup.UserFields.ConditionList[num2] = Convert.ToUInt32(value2, 16);
				num2++;
			}
		}
	}
}
