using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class TlvDownloadResponseInfo : PacketInfoBase
{
	public override string Name => "Tlv Download Response";

	public override string DisplayGroup => "Vendor Specific";

	public TlvDownloadResponseInfo(TlvDownloadResponse packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		TlvDownloadResponse tlvDownloadResponse = (TlvDownloadResponse)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Command Response", "Response to command request", 8, FormatValue(tlvDownloadResponse.UserFields.CommandResponse, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Response type - Sub-Opcode", "Response type - Sub-Opcode", 8, FormatValue(tlvDownloadResponse.UserFields.ResponseTypeSubOpcode, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Status", "EDL Status Info\r\n\r\n" + EdlErrorCodeInfo.EdlErrorCodeToDescription(), 8, FormatValue(tlvDownloadResponse.UserFields.Status, 8), EdlErrorCodeInfo.EdlErrorCodeToString(EdlErrorCodeInfo.ValueToEdlErrorCode(tlvDownloadResponse.UserFields.Status)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		TlvDownloadResponse tlvDownloadResponse = (TlvDownloadResponse)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 ResponseTypeSubOpcode");
		}
		if (index == ++num)
		{
			tlvDownloadResponse.UserFields.Status = Convert.ToUInt32(value, 16);
		}
	}
}
