using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class LeSetCigParametersInfo : PacketInfoBase
{
	public override string Name => "Le Set Cig Parameters";

	public override string DisplayGroup => "LE Controller";

	public LeSetCigParametersInfo(LeSetCigParameters packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		LeSetCigParameters leSetCigParameters = (LeSetCigParameters)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("CIG_ID", "", 8, FormatValue(leSetCigParameters.UserFields.CigId, 8), "", "0", "EF", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("SDU_Interval_M_TO_S", "Interval in microseconds of periodic SDUs.", 24, FormatValue(leSetCigParameters.UserFields.SduIntervalMToS, 24), "", "FF", "FFFFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("SDU_Interval_S_TO_M", "Interval in microseconds of periodic SDUs.", 24, FormatValue(leSetCigParameters.UserFields.SduIntervalSToM, 24), "", "FF", "FFFFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("SCA", "Slave’s sleep clock accuracy.\r\n\r\n" + ClockAccuracyInfo.ClockAccuracyToDescription(), 8, FormatValue(leSetCigParameters.UserFields.Sca, 8), ClockAccuracyInfo.ClockAccuracyToString(ClockAccuracyInfo.ValueToClockAccuracy(leSetCigParameters.UserFields.Sca)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Packing", IsoPackingInfo.IsoPackingToDescription(), 8, FormatValue(leSetCigParameters.UserFields.Packing, 8), IsoPackingInfo.IsoPackingToString(IsoPackingInfo.ValueToIsoPacking(leSetCigParameters.UserFields.Packing)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Framing", IsoFramingInfo.IsoFramingToDescription(), 8, FormatValue(leSetCigParameters.UserFields.Framing, 8), IsoFramingInfo.IsoFramingToString(IsoFramingInfo.ValueToIsoFraming(leSetCigParameters.UserFields.Framing)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Max_Transport_Latency_M_TO_S", "The transport delay time in miliseconds.", 16, FormatValue(leSetCigParameters.UserFields.MaxTransportLatencyMToS, 16), "", "0005", "0FA0", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Max_Transport_Latency_S_TO_M", "The transport delay time in miliseconds.", 16, FormatValue(leSetCigParameters.UserFields.MaxTransportLatencySToM, 16), "", "0005", "0FA0", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("CIS_Count", "Total number of Connected Isochronous Stream.", 8, FormatValue(leSetCigParameters.UserFields.CisCount, 8), "", "0", "1F", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		for (int i = 0; i < leSetCigParameters.UserFields.CisParametersList.Count; i++)
		{
			fieldInfoList.Add(new PacketFieldInfo("CIS_ID[" + i + "]", "Used to identify a Connected Isochronous Stream.", 8, FormatValue(leSetCigParameters.UserFields.CisParametersList[i].CisId, 8), "", "0", "EF", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("Max_SDU_M_TO_S[" + i + "]", "Maximum size of an SDU in octets from the master Host.", 16, FormatValue(leSetCigParameters.UserFields.CisParametersList[i].MaxSduMToS, 16), "", "0", "FFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("Max_SDU_S_TO_M[" + i + "]", "Maximum size of an SDU in octets from the slave Host.", 16, FormatValue(leSetCigParameters.UserFields.CisParametersList[i].MaxSduSToM, 16), "", "0", "FFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("PHY_M_TO_S[" + i + "]", TransmitterPhyPreferenceInfo.TransmitterPhyPreferenceToDescription(), 8, FormatValue(leSetCigParameters.UserFields.CisParametersList[i].PhyMToS, 8), TransmitterPhyPreferenceInfo.TransmitterPhyPreferenceToString(TransmitterPhyPreferenceInfo.ValueToTransmitterPhyPreference(leSetCigParameters.UserFields.CisParametersList[i].PhyMToS)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("PHY_S_TO_M[" + i + "]", TransmitterPhyPreferenceInfo.TransmitterPhyPreferenceToDescription(), 8, FormatValue(leSetCigParameters.UserFields.CisParametersList[i].PhySToM, 8), TransmitterPhyPreferenceInfo.TransmitterPhyPreferenceToString(TransmitterPhyPreferenceInfo.ValueToTransmitterPhyPreference(leSetCigParameters.UserFields.CisParametersList[i].PhySToM)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("RTN_M_TO_S[" + i + "]", "Maximum number of times every CIS Data PDU should be retransmitted from the master to slave.", 8, FormatValue(leSetCigParameters.UserFields.CisParametersList[i].RtnMToS, 8), "", "0", "F", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("RTN_S_TO_M[" + i + "]", "Maximum number of times every CIS Data PDU should be retransmitted from the slave to master.", 8, FormatValue(leSetCigParameters.UserFields.CisParametersList[i].RtnSToM, 8), "", "0", "F", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		}
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		LeSetCigParameters leSetCigParameters = (LeSetCigParameters)packet;
		int num = -1;
		if (index == ++num)
		{
			leSetCigParameters.UserFields.CigId = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			leSetCigParameters.UserFields.SduIntervalMToS = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			leSetCigParameters.UserFields.SduIntervalSToM = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			leSetCigParameters.UserFields.Sca = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			leSetCigParameters.UserFields.Packing = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			leSetCigParameters.UserFields.Framing = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			leSetCigParameters.UserFields.MaxTransportLatencyMToS = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			leSetCigParameters.UserFields.MaxTransportLatencySToM = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			leSetCigParameters.UserFields.CisCount = Convert.ToUInt32(value, 16);
			return;
		}
		for (int i = 0; i < leSetCigParameters.UserFields.CisParametersList.Count; i++)
		{
			if (index == ++num)
			{
				leSetCigParameters.UserFields.CisParametersList[i].CisId = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				leSetCigParameters.UserFields.CisParametersList[i].MaxSduMToS = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				leSetCigParameters.UserFields.CisParametersList[i].MaxSduSToM = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				leSetCigParameters.UserFields.CisParametersList[i].PhyMToS = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				leSetCigParameters.UserFields.CisParametersList[i].PhySToM = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				leSetCigParameters.UserFields.CisParametersList[i].RtnMToS = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				leSetCigParameters.UserFields.CisParametersList[i].RtnSToM = Convert.ToUInt32(value, 16);
				break;
			}
		}
	}
}
