using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class SetConnectionlessSlaveBroadcastDataInfo : PacketInfoBase
{
	public override string Name => "Set Connectionless Slave Broadcast Data";

	public override string DisplayGroup => "Host Control and Baseband";

	public SetConnectionlessSlaveBroadcastDataInfo(SetConnectionlessSlaveBroadcastData packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		SetConnectionlessSlaveBroadcastData setConnectionlessSlaveBroadcastData = (SetConnectionlessSlaveBroadcastData)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("LT_ADDR", SetConnectionlessSlaveBroadcastData.UserFieldsWrapper.LtAddrInfo.LtAddrToDescription(), 8, FormatValue(setConnectionlessSlaveBroadcastData.UserFields.LtAddr, 8), SetConnectionlessSlaveBroadcastData.UserFieldsWrapper.LtAddrInfo.LtAddrToString(SetConnectionlessSlaveBroadcastData.UserFieldsWrapper.LtAddrInfo.ValueToLtAddr(setConnectionlessSlaveBroadcastData.UserFields.LtAddr)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Fragment", SetConnectionlessSlaveBroadcastData.UserFieldsWrapper.FragmentInfo.FragmentToDescription(), 8, FormatValue(setConnectionlessSlaveBroadcastData.UserFields.Fragment, 8), SetConnectionlessSlaveBroadcastData.UserFieldsWrapper.FragmentInfo.FragmentToString(SetConnectionlessSlaveBroadcastData.UserFieldsWrapper.FragmentInfo.ValueToFragment(setConnectionlessSlaveBroadcastData.UserFields.Fragment)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Data_Length", "Length of the Data field", 8, FormatValue(setConnectionlessSlaveBroadcastData.UserFields.DataLength, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Data", "Data to send in future Connectionless Slave Broadcast packets. This data will be repeated in future Connectionless Slave Broadcast instants until new data is provided", setConnectionlessSlaveBroadcastData.UserFields.DataList.Count * 8, FormatValue(setConnectionlessSlaveBroadcastData.UserFields.DataList, setConnectionlessSlaveBroadcastData.UserFields.DataList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		SetConnectionlessSlaveBroadcastData setConnectionlessSlaveBroadcastData = (SetConnectionlessSlaveBroadcastData)packet;
		int num = -1;
		if (index == ++num)
		{
			setConnectionlessSlaveBroadcastData.UserFields.LtAddr = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			setConnectionlessSlaveBroadcastData.UserFields.Fragment = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			setConnectionlessSlaveBroadcastData.UserFields.DataLength = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			value = AddLeadingZerosAndCheckValueStringLength(value, setConnectionlessSlaveBroadcastData.UserFields.DataList.Count);
			int num2 = 0;
			while (value.Length > 0)
			{
				string value2 = value.Substring(0, 2);
				value = value.Remove(0, 2);
				setConnectionlessSlaveBroadcastData.UserFields.DataList[num2] = Convert.ToUInt32(value2, 16);
				num2++;
			}
		}
	}
}
