using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class SynchronousConnectionCompleteEventInfo : PacketInfoBase
{
	public override string Name => "Synchronous Connection Complete Event";

	public override string DisplayGroup => "Link Control";

	public SynchronousConnectionCompleteEventInfo(SynchronousConnectionCompleteEvent packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		SynchronousConnectionCompleteEvent synchronousConnectionCompleteEvent = (SynchronousConnectionCompleteEvent)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Status", ErrorCodeInfo.ErrorCodeToDescription(), 8, FormatValue(synchronousConnectionCompleteEvent.UserFields.Status, 8), ErrorCodeInfo.ErrorCodeToString(ErrorCodeInfo.ValueToErrorCode(synchronousConnectionCompleteEvent.UserFields.Status)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Connection Handle", "Connection_Handle for which the Link Key has been changed for all devices in the same piconet.", 16, FormatValue(synchronousConnectionCompleteEvent.UserFields.ConnectionHandle, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("BD_ADDR", "BD_ADDR of the other connected device forming the connection", 48, FormatValue(synchronousConnectionCompleteEvent.UserFields.BdAddr, 48), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Link_Type", SynchronousConnectionCompleteEvent.UserFieldsWrapper.LinkTypeInfo.LinkTypeToDescription(), 8, FormatValue(synchronousConnectionCompleteEvent.UserFields.LinkType, 8), SynchronousConnectionCompleteEvent.UserFieldsWrapper.LinkTypeInfo.LinkTypeToString(SynchronousConnectionCompleteEvent.UserFieldsWrapper.LinkTypeInfo.ValueToLinkType(synchronousConnectionCompleteEvent.UserFields.LinkType)), "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Transmission_Interval", "", 8, FormatValue(synchronousConnectionCompleteEvent.UserFields.TransmissionInterval, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Retransmission_window", "", 8, FormatValue(synchronousConnectionCompleteEvent.UserFields.RetransmissionWindow, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Rx_Packet_Length", "", 16, FormatValue(synchronousConnectionCompleteEvent.UserFields.RxPacketLength, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Tx_Packet_Length", "", 16, FormatValue(synchronousConnectionCompleteEvent.UserFields.TxPacketLength, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Air_Mode", SynchronousConnectionCompleteEvent.UserFieldsWrapper.AirModeInfo.AirModeToDescription(), 8, FormatValue(synchronousConnectionCompleteEvent.UserFields.AirMode, 8), SynchronousConnectionCompleteEvent.UserFieldsWrapper.AirModeInfo.AirModeToString(SynchronousConnectionCompleteEvent.UserFieldsWrapper.AirModeInfo.ValueToAirMode(synchronousConnectionCompleteEvent.UserFields.AirMode)), "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		SynchronousConnectionCompleteEvent synchronousConnectionCompleteEvent = (SynchronousConnectionCompleteEvent)packet;
		int num = -1;
		if (index == ++num)
		{
			synchronousConnectionCompleteEvent.UserFields.Status = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			synchronousConnectionCompleteEvent.UserFields.ConnectionHandle = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			synchronousConnectionCompleteEvent.UserFields.BdAddr = Convert.ToUInt64(value, 16);
		}
		else if (index == ++num)
		{
			synchronousConnectionCompleteEvent.UserFields.LinkType = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			synchronousConnectionCompleteEvent.UserFields.TransmissionInterval = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			synchronousConnectionCompleteEvent.UserFields.RetransmissionWindow = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			synchronousConnectionCompleteEvent.UserFields.RxPacketLength = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			synchronousConnectionCompleteEvent.UserFields.TxPacketLength = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			synchronousConnectionCompleteEvent.UserFields.AirMode = Convert.ToUInt32(value, 16);
		}
	}
}
