using System;
using QCRPG.Framework;

namespace QCRPG.TSL.FM.Packets;

public class RdsTransmitGroupsInfo : PacketInfoBase
{
	public override string Name => "Rds Transmit Groups";

	public override string DisplayGroup => "RDS Control";

	public RdsTransmitGroupsInfo(RdsTransmitGroups packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		RdsTransmitGroups rdsTransmitGroups = (RdsTransmitGroups)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Register Address", RegisterMapInfo.RegisterMapToDescription(), 8, FormatValue(rdsTransmitGroups.UserFields.RegisterAddress, 8), RegisterMapInfo.RegisterMapToString(RegisterMapInfo.ValueToRegisterMap(rdsTransmitGroups.UserFields.RegisterAddress)), "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("XFR Mode", XfrModeMapInfo.XfrModeMapToDescription(), 8, FormatValue(rdsTransmitGroups.UserFields.XfrMode, 8), XfrModeMapInfo.XfrModeMapToString(XfrModeMapInfo.ValueToXfrModeMap(rdsTransmitGroups.UserFields.XfrMode)), "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Add Group", RdsTransmitGroups.UserFieldsWrapper.AddGroupInfo.AddGroupToDescription(), 1, FormatValue(rdsTransmitGroups.UserFields.AddGroup, 1), RdsTransmitGroups.UserFieldsWrapper.AddGroupInfo.AddGroupToString(RdsTransmitGroups.UserFieldsWrapper.AddGroupInfo.ValueToAddGroup(rdsTransmitGroups.UserFields.AddGroup)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Undefined", "", 5, FormatValue(rdsTransmitGroups.UserFields.Undefined, 5), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Control", "RDS group buffer flush timer (sec) to prevent data from sitting in buffer; 0 = disable flush timer\r\n\r\n" + RdsTransmitGroups.UserFieldsWrapper.ControlInfo.ControlToDescription(), 2, FormatValue(rdsTransmitGroups.UserFields.Control, 2), RdsTransmitGroups.UserFieldsWrapper.ControlInfo.ControlToString(RdsTransmitGroups.UserFieldsWrapper.ControlInfo.ValueToControl(rdsTransmitGroups.UserFields.Control)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("RDS Group", "RDS block 1-4 information bits", 64, FormatValue(rdsTransmitGroups.UserFields.RdsGroup, 64), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		RdsTransmitGroups rdsTransmitGroups = (RdsTransmitGroups)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 XfrMode");
		}
		if (index == ++num)
		{
			rdsTransmitGroups.UserFields.AddGroup = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field Undefined");
		}
		if (index == ++num)
		{
			rdsTransmitGroups.UserFields.Control = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			rdsTransmitGroups.UserFields.RdsGroup = Convert.ToUInt64(value, 16);
		}
	}
}
