using System;
using QCRPG.Framework;

namespace QCRPG.TSL.FM.Packets;

public class RdsControlInfo : PacketInfoBase
{
	public override string Name => "Rds Control";

	public override string DisplayGroup => "RDS Control";

	public RdsControlInfo(RdsControl packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		RdsControl rdsControl = (RdsControl)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Register Address", RegisterMapInfo.RegisterMapToDescription(), 8, FormatValue(rdsControl.UserFields.RegisterAddress, 8), RegisterMapInfo.RegisterMapToString(RegisterMapInfo.ValueToRegisterMap(rdsControl.UserFields.RegisterAddress)), "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Undefined", "", 5, FormatValue(rdsControl.UserFields.Undefined, 5), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Synchronization", RdsControl.UserFieldsWrapper.SynchronizationInfo.SynchronizationToDescription(), 1, FormatValue(rdsControl.UserFields.Synchronization, 1), RdsControl.UserFieldsWrapper.SynchronizationInfo.SynchronizationToString(RdsControl.UserFieldsWrapper.SynchronizationInfo.ValueToSynchronization(rdsControl.UserFields.Synchronization)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Standard", RdsControl.UserFieldsWrapper.StandardInfo.StandardToDescription(), 1, FormatValue(rdsControl.UserFields.Standard, 1), RdsControl.UserFieldsWrapper.StandardInfo.StandardToString(RdsControl.UserFieldsWrapper.StandardInfo.ValueToStandard(rdsControl.UserFields.Standard)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Control", RdsControl.UserFieldsWrapper.ControlInfo.ControlToDescription(), 1, FormatValue(rdsControl.UserFields.Control, 1), RdsControl.UserFieldsWrapper.ControlInfo.ControlToString(RdsControl.UserFieldsWrapper.ControlInfo.ValueToControl(rdsControl.UserFields.Control)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		RdsControl rdsControl = (RdsControl)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 Undefined");
		}
		if (index == ++num)
		{
			rdsControl.UserFields.Synchronization = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			rdsControl.UserFields.Standard = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			rdsControl.UserFields.Control = Convert.ToUInt32(value, 16);
		}
	}
}
