using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class LeSetupIsoDataPathInfo : PacketInfoBase
{
	public override string Name => "Le Setup Iso Data Path";

	public override string DisplayGroup => "LE Controller";

	public LeSetupIsoDataPathInfo(LeSetupIsoDataPath packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		LeSetupIsoDataPath leSetupIsoDataPath = (LeSetupIsoDataPath)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Connection_Handle", "", 16, FormatValue(leSetupIsoDataPath.UserFields.ConnectionHandle, 16), "", "0000", "0EFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Data_Path_Direction", IsoDataPathDirectionInfo.IsoDataPathDirectionToDescription(), 8, FormatValue(leSetupIsoDataPath.UserFields.DataPathDirection, 8), IsoDataPathDirectionInfo.IsoDataPathDirectionToString(IsoDataPathDirectionInfo.ValueToIsoDataPathDirection(leSetupIsoDataPath.UserFields.DataPathDirection)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Data_Path_ID", IsoDataPathIdInfo.IsoDataPathIdToDescription(), 8, FormatValue(leSetupIsoDataPath.UserFields.DataPathId, 8), IsoDataPathIdInfo.IsoDataPathIdToString(IsoDataPathIdInfo.ValueToIsoDataPathId(leSetupIsoDataPath.UserFields.DataPathId)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Codec_ID", "", 40, FormatValue(leSetupIsoDataPath.UserFields.CodecId, 40), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Controller_Delay", "", 24, FormatValue(leSetupIsoDataPath.UserFields.ControllerDelay, 24), "", "000000", "3D0900", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Codec_CFG_Length", "", 8, FormatValue(leSetupIsoDataPath.UserFields.CodecCfgLength, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Codec_CFG", "", leSetupIsoDataPath.UserFields.CodecCfgList.Count * 8, FormatValue(leSetupIsoDataPath.UserFields.CodecCfgList, leSetupIsoDataPath.UserFields.CodecCfgList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		LeSetupIsoDataPath leSetupIsoDataPath = (LeSetupIsoDataPath)packet;
		int num = -1;
		if (index == ++num)
		{
			leSetupIsoDataPath.UserFields.ConnectionHandle = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leSetupIsoDataPath.UserFields.DataPathDirection = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leSetupIsoDataPath.UserFields.DataPathId = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leSetupIsoDataPath.UserFields.CodecId = Convert.ToUInt64(value, 16);
		}
		else if (index == ++num)
		{
			leSetupIsoDataPath.UserFields.ControllerDelay = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leSetupIsoDataPath.UserFields.CodecCfgLength = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			value = AddLeadingZerosAndCheckValueStringLength(value, leSetupIsoDataPath.UserFields.CodecCfgList.Count);
			int num2 = 0;
			while (value.Length > 0)
			{
				string value2 = value.Substring(0, 2);
				value = value.Remove(0, 2);
				leSetupIsoDataPath.UserFields.CodecCfgList[num2] = Convert.ToUInt32(value2, 16);
				num2++;
			}
		}
	}
}
