using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class TwsEscoSetupInfo : PacketInfoBase
{
	public override string Name => "Tws Esco Setup";

	public override string DisplayGroup => "Vendor Specific";

	public TwsEscoSetupInfo(TwsEscoSetup packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		TwsEscoSetup twsEscoSetup = (TwsEscoSetup)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Sub OpCode", "HCI_VS_TWS_eSCO_SETUP", 8, FormatValue(twsEscoSetup.UserFields.SubOpcode, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("BD_ADDR_LEFT", "", 48, FormatValue(twsEscoSetup.UserFields.BdAddrLeft, 48), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("BD_ADDR_RIGHT", "", 48, FormatValue(twsEscoSetup.UserFields.BdAddrRight, 48), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Microphone_Path", TwsEscoSetup.UserFieldsWrapper.MicrophonePathInfo.MicrophonePathToDescription(), 8, FormatValue(twsEscoSetup.UserFields.MicrophonePath, 8), TwsEscoSetup.UserFieldsWrapper.MicrophonePathInfo.MicrophonePathToString(TwsEscoSetup.UserFieldsWrapper.MicrophonePathInfo.ValueToMicrophonePath(twsEscoSetup.UserFields.MicrophonePath)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		TwsEscoSetup twsEscoSetup = (TwsEscoSetup)packet;
		int num = -1;
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field SubOpcode");
		}
		if (index == ++num)
		{
			twsEscoSetup.UserFields.BdAddrLeft = Convert.ToUInt64(value, 16);
		}
		else if (index == ++num)
		{
			twsEscoSetup.UserFields.BdAddrRight = Convert.ToUInt64(value, 16);
		}
		else if (index == ++num)
		{
			twsEscoSetup.UserFields.MicrophonePath = Convert.ToUInt32(value, 16);
		}
	}
}
