using System;
using QCRPG.Framework;

namespace QCRPG.TSL.FM.Packets;

public class RadioControlInfo : PacketInfoBase
{
	public override string Name => "Radio Control";

	public override string DisplayGroup => "Control";

	public RadioControlInfo(RadioControl packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		RadioControl radioControl = (RadioControl)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Register Address", RegisterMapInfo.RegisterMapToDescription(), 8, FormatValue(radioControl.UserFields.RegisterAddress, 8), RegisterMapInfo.RegisterMapToString(RegisterMapInfo.ValueToRegisterMap(radioControl.UserFields.RegisterAddress)), "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("High And Low Side Injection", RadioControl.UserFieldsWrapper.HighAndLowSideInjectionInfo.HighAndLowSideInjectionToDescription(), 2, FormatValue(radioControl.UserFields.HighAndLowSideInjection, 2), RadioControl.UserFieldsWrapper.HighAndLowSideInjectionInfo.HighAndLowSideInjectionToString(RadioControl.UserFieldsWrapper.HighAndLowSideInjectionInfo.ValueToHighAndLowSideInjection(radioControl.UserFields.HighAndLowSideInjection)), "", "2", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Emphasis", RadioControl.UserFieldsWrapper.EmphasisInfo.EmphasisToDescription(), 1, FormatValue(radioControl.UserFields.Emphasis, 1), RadioControl.UserFieldsWrapper.EmphasisInfo.EmphasisToString(RadioControl.UserFieldsWrapper.EmphasisInfo.ValueToEmphasis(radioControl.UserFields.Emphasis)), "", "1", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Channel Spacing", RadioControl.UserFieldsWrapper.ChannelSpacingInfo.ChannelSpacingToDescription(), 2, FormatValue(radioControl.UserFields.ChannelSpacing, 2), RadioControl.UserFieldsWrapper.ChannelSpacingInfo.ChannelSpacingToString(RadioControl.UserFieldsWrapper.ChannelSpacingInfo.ValueToChannelSpacing(radioControl.UserFields.ChannelSpacing)), "", "2", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Band", RadioControl.UserFieldsWrapper.BandInfo.BandToDescription(), 1, FormatValue(radioControl.UserFields.Band, 1), RadioControl.UserFieldsWrapper.BandInfo.BandToString(RadioControl.UserFieldsWrapper.BandInfo.ValueToBand(radioControl.UserFields.Band)), "", "1", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Radio Control", RadioControl.UserFieldsWrapper.RadioControlInfo.RadioControlToDescription(), 2, FormatValue(radioControl.UserFields.RadioControl, 2), RadioControl.UserFieldsWrapper.RadioControlInfo.RadioControlToString(RadioControl.UserFieldsWrapper.RadioControlInfo.ValueToRadioControl(radioControl.UserFields.RadioControl)), "", "3", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		RadioControl radioControl = (RadioControl)packet;
		int num = -1;
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field RegisterAddress");
		}
		if (index == ++num)
		{
			radioControl.UserFields.HighAndLowSideInjection = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			radioControl.UserFields.Emphasis = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			radioControl.UserFields.ChannelSpacing = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			radioControl.UserFields.Band = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			radioControl.UserFields.RadioControl = Convert.ToUInt32(value, 16);
		}
	}
}
