using System;
using QCRPG.Framework;

namespace QCRPG.TSL.FMHCI.Packets;

public class SearchListCompleteInfo : PacketInfoBase
{
	public override string Name => "Search List Complete";

	public override string DisplayGroup => "Events";

	public SearchListCompleteInfo(SearchListComplete packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		SearchListComplete searchListComplete = (SearchListComplete)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Status", ErrorCodeInfo.ErrorCodeToDescription(), 8, FormatValue(searchListComplete.UserFields.Status, 8), ErrorCodeInfo.ErrorCodeToString(ErrorCodeInfo.ValueToErrorCode(searchListComplete.UserFields.Status)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Number Of Stations Found", "", 8, FormatValue(searchListComplete.UserFields.NumberOfStationsFound, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		for (int i = 0; i < searchListComplete.UserFields.StationListList.Count; i++)
		{
			fieldInfoList.Add(new PacketFieldInfo("Station Frequency[" + i + "]", "", 32, FormatValue(searchListComplete.UserFields.StationListList[i].StationFrequency, 32), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("RDS Capability[" + i + "]", SearchListComplete.StationListSubField.RdsCapabilityInfo.RdsCapabilityToDescription(), 8, FormatValue(searchListComplete.UserFields.StationListList[i].RdsCapability, 8), SearchListComplete.StationListSubField.RdsCapabilityInfo.RdsCapabilityToString(SearchListComplete.StationListSubField.RdsCapabilityInfo.ValueToRdsCapability(searchListComplete.UserFields.StationListList[i].RdsCapability)), "", "1", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("Program Type[" + i + "]", "", 8, FormatValue(searchListComplete.UserFields.StationListList[i].ProgramType, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("Program Identification Code[" + i + "]", "", 16, FormatValue(searchListComplete.UserFields.StationListList[i].ProgramIdentificationCode, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		}
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		SearchListComplete searchListComplete = (SearchListComplete)packet;
		int num = -1;
		if (index == ++num)
		{
			searchListComplete.UserFields.Status = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			searchListComplete.UserFields.NumberOfStationsFound = Convert.ToUInt32(value, 16);
			return;
		}
		for (int i = 0; i < searchListComplete.UserFields.StationListList.Count; i++)
		{
			if (index == ++num)
			{
				searchListComplete.UserFields.StationListList[i].StationFrequency = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				searchListComplete.UserFields.StationListList[i].RdsCapability = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				searchListComplete.UserFields.StationListList[i].ProgramType = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				searchListComplete.UserFields.StationListList[i].ProgramIdentificationCode = Convert.ToUInt32(value, 16);
				break;
			}
		}
	}
}
