using System;
using QCRPG.Framework;

namespace QCRPG.TSL.FMHCI.Packets;

public class EdlSetPatchHeaderRequestInfo : PacketInfoBase
{
	public override string Name => "Edl Set Patch Header Request";

	public override string DisplayGroup => "Firmware Patching";

	public EdlSetPatchHeaderRequestInfo(EdlSetPatchHeaderRequest packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		EdlSetPatchHeaderRequest edlSetPatchHeaderRequest = (EdlSetPatchHeaderRequest)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Sub OpCode", "EDL_SET_PATCH_HEADER_REQUEST", 8, FormatValue(edlSetPatchHeaderRequest.UserFields.SubOpcode, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Product ID", "Patch product ID", 32, FormatValue(edlSetPatchHeaderRequest.UserFields.ProductId, 32), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Build Version", "Patch build version", 32, FormatValue(edlSetPatchHeaderRequest.UserFields.BuildVersion, 32), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Base Address", "Patch base address", 32, FormatValue(edlSetPatchHeaderRequest.UserFields.BaseAddress, 32), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Entry Address", "Patch entry address", 32, FormatValue(edlSetPatchHeaderRequest.UserFields.EntryAddress, 32), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Length", "Patch length", 32, FormatValue(edlSetPatchHeaderRequest.UserFields.Length, 32), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("CRC", "Patch CRC", 32, FormatValue(edlSetPatchHeaderRequest.UserFields.Crc, 32), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Control bits", "Patch control bits; bit 31 = reset control; bit 0 = 1 apply after reset; bit 0 = 0 apply before reset", 32, FormatValue(edlSetPatchHeaderRequest.UserFields.ControlBits, 32), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

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