using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class ReadClockOffsetCompleteInfo : PacketInfoBase
{
	public override string Name => "Read Clock Offset Complete";

	public override string DisplayGroup => "Link Control";

	public ReadClockOffsetCompleteInfo(ReadClockOffsetComplete packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		ReadClockOffsetComplete readClockOffsetComplete = (ReadClockOffsetComplete)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Status", ErrorCodeInfo.ErrorCodeToDescription(), 8, FormatValue(readClockOffsetComplete.UserFields.Status, 8), ErrorCodeInfo.ErrorCodeToString(ErrorCodeInfo.ValueToErrorCode(readClockOffsetComplete.UserFields.Status)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Connection_Handle", "Specifies which Connection_Handle's Clock Offset parameter is returned.", 16, FormatValue(readClockOffsetComplete.UserFields.ConnectionHandle, 16), "", "0000", "0EFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Clock_Offset", "Bit 14-0 = Bit 16-2 of CLKNslave-CLK, Bit 15 = Reserved", 16, FormatValue(readClockOffsetComplete.UserFields.ClockOffset, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		ReadClockOffsetComplete readClockOffsetComplete = (ReadClockOffsetComplete)packet;
		int num = -1;
		if (index == ++num)
		{
			readClockOffsetComplete.UserFields.Status = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			readClockOffsetComplete.UserFields.ConnectionHandle = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			readClockOffsetComplete.UserFields.ClockOffset = Convert.ToUInt32(value, 16);
		}
	}
}
