using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class PatchVerResponseInfo : PacketInfoBase
{
	public override string Name => "Patch Ver Response";

	public override string DisplayGroup => "Vendor Specific";

	public PatchVerResponseInfo(PatchVerResponse packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		PatchVerResponse patchVerResponse = (PatchVerResponse)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Command Response", "Response to command request", 8, FormatValue(patchVerResponse.UserFields.CommandResponse, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Response type", "PATCH_VER_RESPONSE", 8, FormatValue(patchVerResponse.UserFields.ResponseType, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Product ID", "Product ID", 32, FormatValue(patchVerResponse.UserFields.ProductId, 32), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Patch Version", "Patch version", 16, FormatValue(patchVerResponse.UserFields.PatchVersion, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("ROM Build Version", "ROM Build Version", 16, FormatValue(patchVerResponse.UserFields.RomBuildVersion, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("SOC Version", "SOC Version", 32, FormatValue(patchVerResponse.UserFields.SocVersion, 32), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		PatchVerResponse patchVerResponse = (PatchVerResponse)packet;
		int num = -1;
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field CommandResponse");
		}
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field ResponseType");
		}
		if (index == ++num)
		{
			patchVerResponse.UserFields.ProductId = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			patchVerResponse.UserFields.PatchVersion = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			patchVerResponse.UserFields.RomBuildVersion = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			patchVerResponse.UserFields.SocVersion = Convert.ToUInt32(value, 16);
		}
	}
}
