using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class SamStatusChangeInfo : PacketInfoBase
{
	public override string Name => "Sam Status Change";

	public override string DisplayGroup => "Link Control";

	public SamStatusChangeInfo(SamStatusChange packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		SamStatusChange samStatusChange = (SamStatusChange)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Connection_Handle", "Connection_Handle. Range: 0x0000-0x0EFF (0x0F00 - 0x0FFF Reserved for future use)", 16, FormatValue(samStatusChange.UserFields.ConnectionHandle, 16), "", "0000", "0EFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Local_SAM_Index", "The index of the current SAM slot map used by the local device.0xFF means SAM is disabled (i.e. all slots are available)", 8, FormatValue(samStatusChange.UserFields.LocalSamIndex, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Local_SAM_TX_Availability", "The proportion of slots available for the local device to transmit. 0 represents \"less than 1 in 255\" and 255 represents \"all\"; other proportions shall be linearly scaled. That is, Local_SAM_TX_Availability = (total_available_TX_slots / local_TSAM) * 255, rounded to the integer below, where total_available_TX_slots is the total number of slots available for transmission in the current local SAM slot map and local_TSAM is TSAM for the current local SAM slot map.", 8, FormatValue(samStatusChange.UserFields.LocalSamTxAvailability, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Local_SAM_RX_Availability", "The proportion of slots available for the local device to transmit. 0 represents \"less than 1 in 255\" and 255 represents \"all\"; other proportions shall be linearly scaled. That is, Local_SAM_RX_Availability = (total_available_RX_slots / local_TSAM) * 255, rounded to the integer below, where total_available_TX_slots is the total number of slots available for reception in the current local SAM slot map and local_TSAM is TSAM for the current local SAM slot map.", 8, FormatValue(samStatusChange.UserFields.LocalSamRxAvailability, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Remote_SAM_Index", "The index of the current SAM slot map used by the remote device.0xFF means SAM is disabled (i.e. all slots are available)", 8, FormatValue(samStatusChange.UserFields.RemoteSamIndex, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Remote_SAM_TX_Availability", "The proportion of slots available for the remote device to transmit. 0 represents \"less than 1 in 255\" and 255 represents \"all\"; other proportions shall be linearly scaled. That is, Remote_SAM_TX_Availability = (total_available_TX_slots / remote_TSAM) * 255, rounded to the integer below, where total_available_TX_slots is the total number of slots available for transmission in the current remote SAM slot map and local_TSAM is TSAM for the current remote SAM slot map.", 8, FormatValue(samStatusChange.UserFields.RemoteSamTxAvailability, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Remote_SAM_RX_Availability", "The proportion of slots available for the remote device to transmit. 0 represents \"less than 1 in 255\" and 255 represents \"all\"; other proportions shall be linearly scaled. That is, Remote_SAM_RX_Availability = (total_available_RX_slots / remote_TSAM) * 255, rounded to the integer below, where total_available_TX_slots is the total number of slots available for reception in the current remote SAM slot map and local_TSAM is TSAM for the current remote SAM slot map.", 8, FormatValue(samStatusChange.UserFields.RemoteSamRxAvailability, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		SamStatusChange samStatusChange = (SamStatusChange)packet;
		int num = -1;
		if (index == ++num)
		{
			samStatusChange.UserFields.ConnectionHandle = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			samStatusChange.UserFields.LocalSamIndex = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			samStatusChange.UserFields.LocalSamTxAvailability = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			samStatusChange.UserFields.LocalSamRxAvailability = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			samStatusChange.UserFields.RemoteSamIndex = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			samStatusChange.UserFields.RemoteSamTxAvailability = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			samStatusChange.UserFields.RemoteSamRxAvailability = Convert.ToUInt32(value, 16);
		}
	}
}
