using System;
using QCRPG.Framework;

namespace QCRPG.TSL.FMHCI.Packets;

public class CommandCompleteForPeekInfo : PacketInfoBase
{
	public override string Name => "Command Complete For Peek";

	public override string DisplayGroup => "Production Test Mode";

	public CommandCompleteForPeekInfo(CommandCompleteForPeek packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		CommandCompleteForPeek commandCompleteForPeek = (CommandCompleteForPeek)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Num HCI Command Packets", "", 8, FormatValue(commandCompleteForPeek.UserFields.NumHciCommandPackets, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Command OpCode", CommandOpcodeInfo.CommandOpcodeToDescription(), 16, FormatValue(commandCompleteForPeek.UserFields.CommandOpcode, 16), CommandOpcodeInfo.CommandOpcodeToString(CommandOpcodeInfo.ValueToCommandOpcode(commandCompleteForPeek.UserFields.CommandOpcode)), "", "", settable: false, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Status", ErrorCodeInfo.ErrorCodeToDescription(), 8, FormatValue(commandCompleteForPeek.UserFields.Status, 8), ErrorCodeInfo.ErrorCodeToString(ErrorCodeInfo.ValueToErrorCode(commandCompleteForPeek.UserFields.Status)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Number Of Addresses Read", "Number of addresses read", 8, FormatValue(commandCompleteForPeek.UserFields.NumberOfAddressesRead, 8), "", "", "1F", settable: true, littleEndianTransport: false, omitFromTransport: true, DataEntryMode.RightAlignedHex));
		for (int i = 0; i < commandCompleteForPeek.UserFields.DataListList.Count; i++)
		{
			fieldInfoList.Add(new PacketFieldInfo("Read Data[" + i + "]", "", 32, FormatValue(commandCompleteForPeek.UserFields.DataListList[i].ReadData, 32), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		}
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		CommandCompleteForPeek commandCompleteForPeek = (CommandCompleteForPeek)packet;
		int num = -1;
		if (index == ++num)
		{
			commandCompleteForPeek.UserFields.NumHciCommandPackets = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field CommandOpcode");
		}
		if (index == ++num)
		{
			commandCompleteForPeek.UserFields.Status = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			commandCompleteForPeek.UserFields.NumberOfAddressesRead = Convert.ToUInt32(value, 16);
			return;
		}
		for (int i = 0; i < commandCompleteForPeek.UserFields.DataListList.Count; i++)
		{
			if (index == ++num)
			{
				commandCompleteForPeek.UserFields.DataListList[i].ReadData = Convert.ToUInt32(value, 16);
				break;
			}
		}
	}
}
