using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class EdlReadPsRequestInfo : PacketInfoBase
{
	public override string Name => "Edl Read Ps Request";

	public override string DisplayGroup => "Vendor Specific";

	public EdlReadPsRequestInfo(EdlReadPsRequest packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		EdlReadPsRequest edlReadPsRequest = (EdlReadPsRequest)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Sub OpCode", "EDL_READ_PS_REQUEST", 8, FormatValue(edlReadPsRequest.UserFields.SubOpcode, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("PS Type", "0x00 = OTP; 0x01 = flash/eeprom", 8, FormatValue(edlReadPsRequest.UserFields.PsType, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Offset", "PS offset", 16, FormatValue(edlReadPsRequest.UserFields.Offset, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Data Length", "Length of read PS data", 8, FormatValue(edlReadPsRequest.UserFields.DataLength, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

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