using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class CreateConnectionInfo : PacketInfoBase
{
	public override string Name => "Create Connection";

	public override string DisplayGroup => "Link Control";

	public CreateConnectionInfo(CreateConnection packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		CreateConnection createConnection = (CreateConnection)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("BD Address", "BD_ADDR of the Device to be connected.", 48, FormatValue(createConnection.UserFields.BdAddress, 48), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Packet Type Mask", AclPacketTypeInfo.AclPacketTypeToDescription(), 16, FormatValue(createConnection.UserFields.PacketTypeMask, 16), AclPacketTypeInfo.AclPacketTypeToString(AclPacketTypeInfo.ValueToAclPacketType(createConnection.UserFields.PacketTypeMask)), "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Page Scan Repetition Mode", PageScanRepetitionModeInfo.PageScanRepetitionModeToDescription(), 8, FormatValue(createConnection.UserFields.PageScanRepetitionMode, 8), PageScanRepetitionModeInfo.PageScanRepetitionModeToString(PageScanRepetitionModeInfo.ValueToPageScanRepetitionMode(createConnection.UserFields.PageScanRepetitionMode)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Reserved", "", 8, FormatValue(createConnection.UserFields.Reserved, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Clock Offset", ClockOffsetInfo.ClockOffsetToDescription(), 16, FormatValue(createConnection.UserFields.ClockOffset, 16), ClockOffsetInfo.ClockOffsetToString(ClockOffsetInfo.ValueToClockOffset(createConnection.UserFields.ClockOffset)), "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Allow Role Switch", CreateConnection.UserFieldsWrapper.AllowRoleSwitchInfo.AllowRoleSwitchToDescription(), 8, FormatValue(createConnection.UserFields.AllowRoleSwitch, 8), CreateConnection.UserFieldsWrapper.AllowRoleSwitchInfo.AllowRoleSwitchToString(CreateConnection.UserFieldsWrapper.AllowRoleSwitchInfo.ValueToAllowRoleSwitch(createConnection.UserFields.AllowRoleSwitch)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		CreateConnection createConnection = (CreateConnection)packet;
		int num = -1;
		if (index == ++num)
		{
			createConnection.UserFields.BdAddress = Convert.ToUInt64(value, 16);
			return;
		}
		if (index == ++num)
		{
			createConnection.UserFields.PacketTypeMask = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			createConnection.UserFields.PageScanRepetitionMode = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field Reserved");
		}
		if (index == ++num)
		{
			createConnection.UserFields.ClockOffset = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			createConnection.UserFields.AllowRoleSwitch = Convert.ToUInt32(value, 16);
		}
	}
}
