using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class CommandCompleteForEdlReadPsRequestInfo : PacketInfoBase
{
	public override string Name => "Command Complete For Edl Read Ps Request";

	public override string DisplayGroup => "Vendor Specific";

	public CommandCompleteForEdlReadPsRequestInfo(CommandCompleteForEdlReadPsRequest packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		CommandCompleteForEdlReadPsRequest commandCompleteForEdlReadPsRequest = (CommandCompleteForEdlReadPsRequest)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Num HCI Command Packets", "", 8, FormatValue(commandCompleteForEdlReadPsRequest.UserFields.NumHciCommandPackets, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Command OpCode", CommandOpcodeInfo.CommandOpcodeToDescription(), 16, FormatValue(commandCompleteForEdlReadPsRequest.UserFields.CommandOpcode, 16), CommandOpcodeInfo.CommandOpcodeToString(CommandOpcodeInfo.ValueToCommandOpcode(commandCompleteForEdlReadPsRequest.UserFields.CommandOpcode)), "", "", settable: false, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Status", "EDL Status Info\r\n\r\n" + EdlErrorCodeInfo.EdlErrorCodeToDescription(), 8, FormatValue(commandCompleteForEdlReadPsRequest.UserFields.Status, 8), EdlErrorCodeInfo.EdlErrorCodeToString(EdlErrorCodeInfo.ValueToEdlErrorCode(commandCompleteForEdlReadPsRequest.UserFields.Status)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Sub OpCode", CommandCompleteForEdlReadPsRequest.UserFieldsWrapper.SubOpcodeInfo.SubOpcodeToDescription(), 8, FormatValue(commandCompleteForEdlReadPsRequest.UserFields.SubOpcode, 8), CommandCompleteForEdlReadPsRequest.UserFieldsWrapper.SubOpcodeInfo.SubOpcodeToString(CommandCompleteForEdlReadPsRequest.UserFieldsWrapper.SubOpcodeInfo.ValueToSubOpcode(commandCompleteForEdlReadPsRequest.UserFields.SubOpcode)), "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("PS Type", CommandCompleteForEdlReadPsRequest.UserFieldsWrapper.PsTypeInfo.PsTypeToDescription(), 8, FormatValue(commandCompleteForEdlReadPsRequest.UserFields.PsType, 8), CommandCompleteForEdlReadPsRequest.UserFieldsWrapper.PsTypeInfo.PsTypeToString(CommandCompleteForEdlReadPsRequest.UserFieldsWrapper.PsTypeInfo.ValueToPsType(commandCompleteForEdlReadPsRequest.UserFields.PsType)), "", "01", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Offset", "PS offset", 16, FormatValue(commandCompleteForEdlReadPsRequest.UserFields.Offset, 16), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Data Length", "Length of PS data", 8, FormatValue(commandCompleteForEdlReadPsRequest.UserFields.DataLength, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Data", "", commandCompleteForEdlReadPsRequest.UserFields.DataList.Count * 8, FormatValue(commandCompleteForEdlReadPsRequest.UserFields.DataList, commandCompleteForEdlReadPsRequest.UserFields.DataList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		CommandCompleteForEdlReadPsRequest commandCompleteForEdlReadPsRequest = (CommandCompleteForEdlReadPsRequest)packet;
		int num = -1;
		if (index == ++num)
		{
			commandCompleteForEdlReadPsRequest.UserFields.NumHciCommandPackets = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field CommandOpcode");
		}
		if (index == ++num)
		{
			commandCompleteForEdlReadPsRequest.UserFields.Status = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field SubOpcode");
		}
		if (index == ++num)
		{
			commandCompleteForEdlReadPsRequest.UserFields.PsType = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			commandCompleteForEdlReadPsRequest.UserFields.Offset = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			commandCompleteForEdlReadPsRequest.UserFields.DataLength = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			value = AddLeadingZerosAndCheckValueStringLength(value, commandCompleteForEdlReadPsRequest.UserFields.DataList.Count);
			int num2 = 0;
			while (value.Length > 0)
			{
				string value2 = value.Substring(0, 2);
				value = value.Remove(0, 2);
				commandCompleteForEdlReadPsRequest.UserFields.DataList[num2] = Convert.ToUInt32(value2, 16);
				num2++;
			}
		}
	}
}
