using System;
using QCRPG.Framework;

namespace QCRPG.TSL.FM.Packets;

public class InterruptMaskInfo : PacketInfoBase
{
	public override string Name => "Interrupt Mask";

	public override string DisplayGroup => "Control";

	public InterruptMaskInfo(InterruptMask packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		InterruptMask interruptMask = (InterruptMask)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Register Address", RegisterMapInfo.RegisterMapToDescription(), 8, FormatValue(interruptMask.UserFields.RegisterAddress, 8), RegisterMapInfo.RegisterMapToString(RegisterMapInfo.ValueToRegisterMap(interruptMask.UserFields.RegisterAddress)), "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Audio", "Audio control indicator", 1, FormatValue(interruptMask.UserFields.Audio, 1), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Sync", "RDS synchronization state change", 1, FormatValue(interruptMask.UserFields.Sync, 1), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Interference", "Interference count outside range", 1, FormatValue(interruptMask.UserFields.Interference, 1), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Signal", "Signal indicator change", 1, FormatValue(interruptMask.UserFields.Signal, 1), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Scan Next", "Scanning for next station", 1, FormatValue(interruptMask.UserFields.ScanNext, 1), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Search", "Search completed", 1, FormatValue(interruptMask.UserFields.Search, 1), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Tune", "Tune completed", 1, FormatValue(interruptMask.UserFields.Tune, 1), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Ready", "Radio ready after power up or reset", 1, FormatValue(interruptMask.UserFields.Ready, 1), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("TX RDS Done", "RDS raw group one-shot transmit complete", 1, FormatValue(interruptMask.UserFields.TxRdsDone, 1), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("TX RDS ", "Transmitted an RDS group", 1, FormatValue(interruptMask.UserFields.TxRds, 1), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("RDS AF List Available", "New RDS alternative frequency list available", 1, FormatValue(interruptMask.UserFields.RdsAfListAvailable, 1), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("RDS Radio Text Available", "New RDS radio text available", 1, FormatValue(interruptMask.UserFields.RdsRadioTextAvailable, 1), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("RDS Program Service", "New RDS program service table available", 1, FormatValue(interruptMask.UserFields.RdsProgramService, 1), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Program ID Match", "Block-A or Block-C' matched stored PI value", 1, FormatValue(interruptMask.UserFields.ProgramIdMatch, 1), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Block B Match", "Block-B match condition exists", 1, FormatValue(interruptMask.UserFields.BlockBMatch, 1), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("RDS Data Available", "New unread RDS data group available", 1, FormatValue(interruptMask.UserFields.RdsDataAvailable, 1), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Error", "Error occurred", 1, FormatValue(interruptMask.UserFields.Error, 1), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Undefined", "", 5, FormatValue(interruptMask.UserFields.Undefined, 5), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Dynamic RDS Processing Complete", "Dynamic RDS Processing Complete", 1, FormatValue(interruptMask.UserFields.DynamicRdsProcessingComplete, 1), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Data Transfer Complete", "Data transfer complete", 1, FormatValue(interruptMask.UserFields.DataTransferComplete, 1), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		InterruptMask interruptMask = (InterruptMask)packet;
		int num = -1;
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field RegisterAddress");
		}
		if (index == ++num)
		{
			interruptMask.UserFields.Audio = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			interruptMask.UserFields.Sync = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			interruptMask.UserFields.Interference = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			interruptMask.UserFields.Signal = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			interruptMask.UserFields.ScanNext = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			interruptMask.UserFields.Search = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			interruptMask.UserFields.Tune = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			interruptMask.UserFields.Ready = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			interruptMask.UserFields.TxRdsDone = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			interruptMask.UserFields.TxRds = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			interruptMask.UserFields.RdsAfListAvailable = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			interruptMask.UserFields.RdsRadioTextAvailable = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			interruptMask.UserFields.RdsProgramService = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			interruptMask.UserFields.ProgramIdMatch = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			interruptMask.UserFields.BlockBMatch = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			interruptMask.UserFields.RdsDataAvailable = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			interruptMask.UserFields.Error = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field Undefined");
		}
		if (index == ++num)
		{
			interruptMask.UserFields.DynamicRdsProcessingComplete = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			interruptMask.UserFields.DataTransferComplete = Convert.ToUInt32(value, 16);
		}
	}
}
