using System;
using QCRPG.Framework;

namespace QCRPG.TSL.NFC.Packets;

public class CoreConnCreateRspInfo : PacketInfoBase
{
	public override string Name => "Core Conn Create Rsp";

	public override string DisplayGroup => "NCI Core";

	public CoreConnCreateRspInfo(CoreConnCreateRsp packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		CoreConnCreateRsp coreConnCreateRsp = (CoreConnCreateRsp)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Status", StatusCodesInfo.StatusCodesToDescription(), 8, FormatValue(coreConnCreateRsp.UserFields.Status, 8), StatusCodesInfo.StatusCodesToString(StatusCodesInfo.ValueToStatusCodes(coreConnCreateRsp.UserFields.Status)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Max Data Packet Payload Size", "A number from 32 – 255", 8, FormatValue(coreConnCreateRsp.UserFields.MaxDataPacketPayloadSize, 8), "", "20", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Initial Number of Credits", CoreConnCreateRsp.UserFieldsWrapper.InitialNumberOfCreditsInfo.InitialNumberOfCreditsToDescription(), 8, FormatValue(coreConnCreateRsp.UserFields.InitialNumberOfCredits, 8), CoreConnCreateRsp.UserFieldsWrapper.InitialNumberOfCreditsInfo.InitialNumberOfCreditsToString(CoreConnCreateRsp.UserFieldsWrapper.InitialNumberOfCreditsInfo.ValueToInitialNumberOfCredits(coreConnCreateRsp.UserFields.InitialNumberOfCredits)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Conn ID", "The four least significant bits of the octet SHALL contain the Conn ID as defined in Table 4. The four most significant bits are RFU.", 8, FormatValue(coreConnCreateRsp.UserFields.ConnId, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		CoreConnCreateRsp coreConnCreateRsp = (CoreConnCreateRsp)packet;
		int num = -1;
		if (index == ++num)
		{
			coreConnCreateRsp.UserFields.Status = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			coreConnCreateRsp.UserFields.MaxDataPacketPayloadSize = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			coreConnCreateRsp.UserFields.InitialNumberOfCredits = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			coreConnCreateRsp.UserFields.ConnId = Convert.ToUInt32(value, 16);
		}
	}
}
