using System;
using QCRPG.Framework;

namespace QCRPG.TSL.FM.Packets;

public class StartSearchUsingPiInfo : PacketInfoBase
{
	public override string Name => "Start Search Using Pi";

	public override string DisplayGroup => "Control";

	public StartSearchUsingPiInfo(StartSearchUsingPi packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		StartSearchUsingPi startSearchUsingPi = (StartSearchUsingPi)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Register Address", RegisterMapInfo.RegisterMapToDescription(), 8, FormatValue(startSearchUsingPi.UserFields.RegisterAddress, 8), RegisterMapInfo.RegisterMapToString(RegisterMapInfo.ValueToRegisterMap(startSearchUsingPi.UserFields.RegisterAddress)), "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Program Identification", "RDS Program Identification (PI) to search for", 16, FormatValue(startSearchUsingPi.UserFields.ProgramIdentification, 16), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Search Control", StartSearchUsingPi.UserFieldsWrapper.SearchControlInfo.SearchControlToDescription(), 1, FormatValue(startSearchUsingPi.UserFields.SearchControl, 1), StartSearchUsingPi.UserFieldsWrapper.SearchControlInfo.SearchControlToString(StartSearchUsingPi.UserFieldsWrapper.SearchControlInfo.ValueToSearchControl(startSearchUsingPi.UserFields.SearchControl)), "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Scan Time", "Amount of dwell time (sec) that the FM Controller will stay on a 'good' channel before tuning to the next channel.  Only valid for Scan modes.", 3, FormatValue(startSearchUsingPi.UserFields.ScanTime, 3), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Search Direction", StartSearchUsingPi.UserFieldsWrapper.SearchDirectionInfo.SearchDirectionToDescription(), 1, FormatValue(startSearchUsingPi.UserFields.SearchDirection, 1), StartSearchUsingPi.UserFieldsWrapper.SearchDirectionInfo.SearchDirectionToString(StartSearchUsingPi.UserFieldsWrapper.SearchDirectionInfo.ValueToSearchDirection(startSearchUsingPi.UserFields.SearchDirection)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Search Mode", "Search for program identification", 3, FormatValue(startSearchUsingPi.UserFields.SearchMode, 3), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		StartSearchUsingPi startSearchUsingPi = (StartSearchUsingPi)packet;
		int num = -1;
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field RegisterAddress");
		}
		if (index == ++num)
		{
			startSearchUsingPi.UserFields.ProgramIdentification = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field SearchControl");
		}
		if (index == ++num)
		{
			startSearchUsingPi.UserFields.ScanTime = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			startSearchUsingPi.UserFields.SearchDirection = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field SearchMode");
		}
	}
}
