using System;
using QCRPG.Framework;

namespace QCRPG.TSL.FMHCI.Packets;

public class EdlAppVerResponseInfo : PacketInfoBase
{
	public override string Name => "Edl App Ver Response";

	public override string DisplayGroup => "Firmware Patching";

	public EdlAppVerResponseInfo(EdlAppVerResponse packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		EdlAppVerResponse edlAppVerResponse = (EdlAppVerResponse)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Vendor Download Response", "HCI_DOWNLOAD_EVENT_CODE", 8, FormatValue(edlAppVerResponse.UserFields.VendorDownloadResponse, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Sub OpCode", "EDL_APP_VER_RESPONSE", 8, FormatValue(edlAppVerResponse.UserFields.SubOpcode, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Product ID", "", 32, FormatValue(edlAppVerResponse.UserFields.ProductId, 32), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Build Version", "Current build version", 32, FormatValue(edlAppVerResponse.UserFields.BuildVersion, 32), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		EdlAppVerResponse edlAppVerResponse = (EdlAppVerResponse)packet;
		int num = -1;
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field VendorDownloadResponse");
		}
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field SubOpcode");
		}
		if (index == ++num)
		{
			edlAppVerResponse.UserFields.ProductId = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			edlAppVerResponse.UserFields.BuildVersion = Convert.ToUInt32(value, 16);
		}
	}
}
