using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class SetMptaGrantModeTimeoutInfo : PacketInfoBase
{
	public override string Name => "Set Mpta Grant Mode Timeout";

	public override string DisplayGroup => "Vendor Specific";

	public SetMptaGrantModeTimeoutInfo(SetMptaGrantModeTimeout packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		SetMptaGrantModeTimeout setMptaGrantModeTimeout = (SetMptaGrantModeTimeout)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Sub OpCode", SetMptaGrantModeTimeout.UserFieldsWrapper.SubOpcodeInfo.SubOpcodeToDescription(), 8, FormatValue(setMptaGrantModeTimeout.UserFields.SubOpcode, 8), SetMptaGrantModeTimeout.UserFieldsWrapper.SubOpcodeInfo.SubOpcodeToString(SetMptaGrantModeTimeout.UserFieldsWrapper.SubOpcodeInfo.ValueToSubOpcode(setMptaGrantModeTimeout.UserFields.SubOpcode)), "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("OP Type", SetMptaGrantModeTimeout.UserFieldsWrapper.OpTypeInfo.OpTypeToDescription(), 8, FormatValue(setMptaGrantModeTimeout.UserFields.OpType, 8), SetMptaGrantModeTimeout.UserFieldsWrapper.OpTypeInfo.OpTypeToString(SetMptaGrantModeTimeout.UserFieldsWrapper.OpTypeInfo.ValueToOpType(setMptaGrantModeTimeout.UserFields.OpType)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Time", " Maximum value possible for No Nack Detection Time is 0x1FF.Maximum value possible for other OpTypes is 0x280", 16, FormatValue(setMptaGrantModeTimeout.UserFields.Time, 16), "", "0001", "0280", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

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