using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class EdlUploadRequestInfo : PacketInfoBase
{
	public override string Name => "Edl Upload Request";

	public override string DisplayGroup => "Vendor Specific";

	public EdlUploadRequestInfo(EdlUploadRequest packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		EdlUploadRequest edlUploadRequest = (EdlUploadRequest)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("SubOpCode", "EDL_UPLOAD_REQUEST", 8, FormatValue(edlUploadRequest.UserFields.Subopcode, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Address", "Memory address", 32, FormatValue(edlUploadRequest.UserFields.Address, 32), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Data_Length", "Length of update data", 8, FormatValue(edlUploadRequest.UserFields.DataLength, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		EdlUploadRequest edlUploadRequest = (EdlUploadRequest)packet;
		int num = -1;
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field Subopcode");
		}
		if (index == ++num)
		{
			edlUploadRequest.UserFields.Address = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			edlUploadRequest.UserFields.DataLength = Convert.ToUInt32(value, 16);
		}
	}
}
