using System;
using QCRPG.Framework;

namespace QCRPG.TSL.NFC.Packets;

public class SyntaxErrorResponseInfo : PacketInfoBase
{
	public override string Name => "Syntax Error Response";

	public override string DisplayGroup => "Proprietary/Test";

	public SyntaxErrorResponseInfo(SyntaxErrorResponse packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		SyntaxErrorResponse syntaxErrorResponse = (SyntaxErrorResponse)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("GID", "Group identifier", 4, FormatValue(syntaxErrorResponse.UserFields.Gid, 4), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("OID", "Opcode identifier", 6, FormatValue(syntaxErrorResponse.UserFields.Oid, 6), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Payload Length", "Payload length", 8, FormatValue(syntaxErrorResponse.UserFields.PayloadLength, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Status", "Syntax error status code\r\n\r\n" + StatusCodesInfo.StatusCodesToDescription(), 8, FormatValue(syntaxErrorResponse.UserFields.Status, 8), StatusCodesInfo.StatusCodesToString(StatusCodesInfo.ValueToStatusCodes(syntaxErrorResponse.UserFields.Status)), "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		SyntaxErrorResponse syntaxErrorResponse = (SyntaxErrorResponse)packet;
		int num = -1;
		if (index == ++num)
		{
			syntaxErrorResponse.UserFields.Gid = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			syntaxErrorResponse.UserFields.Oid = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field PayloadLength");
		}
		if (index != ++num)
		{
			return;
		}
		throw new Exception("Tried to set non-settable field Status");
	}
}
