using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

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

	public override string DisplayGroup => "Vendor Specific";

	public EdlSetPatchRegionRequestInfo(EdlSetPatchRegionRequest packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		EdlSetPatchRegionRequest edlSetPatchRegionRequest = (EdlSetPatchRegionRequest)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Sub OpCode", "EDL_SET_PATCH_REGION_REQUEST", 8, FormatValue(edlSetPatchRegionRequest.UserFields.SubOpcode, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("RAM Start", "The start address of the patch region", 32, FormatValue(edlSetPatchRegionRequest.UserFields.RamStart, 32), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Max Length", "Patch max size", 32, FormatValue(edlSetPatchRegionRequest.UserFields.MaxLength, 32), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Used Length", "Patch used length", 32, FormatValue(edlSetPatchRegionRequest.UserFields.UsedLength, 32), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		EdlSetPatchRegionRequest edlSetPatchRegionRequest = (EdlSetPatchRegionRequest)packet;
		int num = -1;
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field SubOpcode");
		}
		if (index == ++num)
		{
			edlSetPatchRegionRequest.UserFields.RamStart = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			edlSetPatchRegionRequest.UserFields.MaxLength = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			edlSetPatchRegionRequest.UserFields.UsedLength = Convert.ToUInt32(value, 16);
		}
	}
}
