using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class LeRequestPeerScaCompleteInfo : PacketInfoBase
{
	public override string Name => "Le Request Peer Sca Complete";

	public override string DisplayGroup => "LE Controller";

	public LeRequestPeerScaCompleteInfo(LeRequestPeerScaComplete packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		LeRequestPeerScaComplete leRequestPeerScaComplete = (LeRequestPeerScaComplete)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Subevent_Code", "Subevent Code for LE_Request_Peer_SCA_Complete event.", 8, FormatValue(leRequestPeerScaComplete.UserFields.SubeventCode, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Status", ErrorCodeInfo.ErrorCodeToDescription(), 8, FormatValue(leRequestPeerScaComplete.UserFields.Status, 8), ErrorCodeInfo.ErrorCodeToString(ErrorCodeInfo.ValueToErrorCode(leRequestPeerScaComplete.UserFields.Status)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Connection_Handle", "Connection Handle is the handle of the ACL connection.", 16, FormatValue(leRequestPeerScaComplete.UserFields.ConnectionHandle, 16), "", "0000", "0EFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("SCA", "Sleep clock accuracy.\r\n\r\n" + ClockAccuracyInfo.ClockAccuracyToDescription(), 8, FormatValue(leRequestPeerScaComplete.UserFields.Sca, 8), ClockAccuracyInfo.ClockAccuracyToString(ClockAccuracyInfo.ValueToClockAccuracy(leRequestPeerScaComplete.UserFields.Sca)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		LeRequestPeerScaComplete leRequestPeerScaComplete = (LeRequestPeerScaComplete)packet;
		int num = -1;
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field SubeventCode");
		}
		if (index == ++num)
		{
			leRequestPeerScaComplete.UserFields.Status = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leRequestPeerScaComplete.UserFields.ConnectionHandle = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leRequestPeerScaComplete.UserFields.Sca = Convert.ToUInt32(value, 16);
		}
	}
}
