using System;
using QCRPG.Framework;

namespace QCRPG.TSL.FM.Packets;

public class StartSearchUsingAfInfo : PacketInfoBase
{
	public override string Name => "Start Search Using Af";

	public override string DisplayGroup => "Control";

	public StartSearchUsingAfInfo(StartSearchUsingAf packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		StartSearchUsingAf startSearchUsingAf = (StartSearchUsingAf)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Register Address", RegisterMapInfo.RegisterMapToDescription(), 8, FormatValue(startSearchUsingAf.UserFields.RegisterAddress, 8), RegisterMapInfo.RegisterMapToString(RegisterMapInfo.ValueToRegisterMap(startSearchUsingAf.UserFields.RegisterAddress)), "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Unused", "", 16, FormatValue(startSearchUsingAf.UserFields.Unused, 16), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Search Control", StartSearchUsingAf.UserFieldsWrapper.SearchControlInfo.SearchControlToDescription(), 1, FormatValue(startSearchUsingAf.UserFields.SearchControl, 1), StartSearchUsingAf.UserFieldsWrapper.SearchControlInfo.SearchControlToString(StartSearchUsingAf.UserFieldsWrapper.SearchControlInfo.ValueToSearchControl(startSearchUsingAf.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(startSearchUsingAf.UserFields.ScanTime, 3), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Search Direction", StartSearchUsingAf.UserFieldsWrapper.SearchDirectionInfo.SearchDirectionToDescription(), 1, FormatValue(startSearchUsingAf.UserFields.SearchDirection, 1), StartSearchUsingAf.UserFieldsWrapper.SearchDirectionInfo.SearchDirectionToString(StartSearchUsingAf.UserFieldsWrapper.SearchDirectionInfo.ValueToSearchDirection(startSearchUsingAf.UserFields.SearchDirection)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Search Mode", "Tune to Alternate Frequency (AF) and stay if signal quality better than current channel", 3, FormatValue(startSearchUsingAf.UserFields.SearchMode, 3), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

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