using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class VsBcaudEnableInfo : PacketInfoBase
{
	public override string Name => "Vs Bcaud Enable";

	public override string DisplayGroup => "Vendor Specific";

	public VsBcaudEnableInfo(VsBcaudEnable packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		VsBcaudEnable vsBcaudEnable = (VsBcaudEnable)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("SubOpCode", "HCI_VS_BCA_TX_CONFIG", 8, FormatValue(vsBcaudEnable.UserFields.Subopcode, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Stream ID", VsBcaudEnable.UserFieldsWrapper.StreamIdInfo.StreamIdToDescription(), 8, FormatValue(vsBcaudEnable.UserFields.StreamId, 8), VsBcaudEnable.UserFieldsWrapper.StreamIdInfo.StreamIdToString(VsBcaudEnable.UserFieldsWrapper.StreamIdInfo.ValueToStreamId(vsBcaudEnable.UserFields.StreamId)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("LT Address", "LT address of CSB", 8, FormatValue(vsBcaudEnable.UserFields.LtAddress, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Codec", VsBcaudEnable.UserFieldsWrapper.CodecInfo.CodecToDescription(), 8, FormatValue(vsBcaudEnable.UserFields.Codec, 8), VsBcaudEnable.UserFieldsWrapper.CodecInfo.CodecToString(VsBcaudEnable.UserFieldsWrapper.CodecInfo.ValueToCodec(vsBcaudEnable.UserFields.Codec)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Sample Rate", VsBcaudEnable.UserFieldsWrapper.SampleRateInfo.SampleRateToDescription(), 8, FormatValue(vsBcaudEnable.UserFields.SampleRate, 8), VsBcaudEnable.UserFieldsWrapper.SampleRateInfo.SampleRateToString(VsBcaudEnable.UserFieldsWrapper.SampleRateInfo.ValueToSampleRate(vsBcaudEnable.UserFields.SampleRate)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Max Packet Size", "", 16, FormatValue(vsBcaudEnable.UserFields.MaxPacketSize, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Encoding Scheme", VsBcaudEnable.UserFieldsWrapper.EncodingSchemeInfo.EncodingSchemeToDescription(), 8, FormatValue(vsBcaudEnable.UserFields.EncodingScheme, 8), VsBcaudEnable.UserFieldsWrapper.EncodingSchemeInfo.EncodingSchemeToString(VsBcaudEnable.UserFieldsWrapper.EncodingSchemeInfo.ValueToEncodingScheme(vsBcaudEnable.UserFields.EncodingScheme)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("TTP Offset in us", "", 32, FormatValue(vsBcaudEnable.UserFields.TtpOffsetInUs, 32), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Private key", "Random key used in encryption", vsBcaudEnable.UserFields.PrivateKeyList.Count * 8, FormatValue(vsBcaudEnable.UserFields.PrivateKeyList, vsBcaudEnable.UserFields.PrivateKeyList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Init Vector", "Random init vector", 64, FormatValue(vsBcaudEnable.UserFields.InitVector, 64), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Volume", "Volume level", 8, FormatValue(vsBcaudEnable.UserFields.Volume, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Transmission power", "", 8, FormatValue(vsBcaudEnable.UserFields.TransmissionPower, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("PCM samples per frame", "", 16, FormatValue(vsBcaudEnable.UserFields.PcmSamplesPerFrame, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		VsBcaudEnable vsBcaudEnable = (VsBcaudEnable)packet;
		int num = -1;
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field Subopcode");
		}
		if (index == ++num)
		{
			vsBcaudEnable.UserFields.StreamId = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			vsBcaudEnable.UserFields.LtAddress = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			vsBcaudEnable.UserFields.Codec = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			vsBcaudEnable.UserFields.SampleRate = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			vsBcaudEnable.UserFields.MaxPacketSize = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			vsBcaudEnable.UserFields.EncodingScheme = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			vsBcaudEnable.UserFields.TtpOffsetInUs = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			value = AddLeadingZerosAndCheckValueStringLength(value, vsBcaudEnable.UserFields.PrivateKeyList.Count);
			int num2 = 0;
			while (value.Length > 0)
			{
				string value2 = value.Substring(0, 2);
				value = value.Remove(0, 2);
				vsBcaudEnable.UserFields.PrivateKeyList[num2] = Convert.ToUInt32(value2, 16);
				num2++;
			}
		}
		if (index == ++num)
		{
			vsBcaudEnable.UserFields.InitVector = Convert.ToUInt64(value, 16);
		}
		else if (index == ++num)
		{
			vsBcaudEnable.UserFields.Volume = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			vsBcaudEnable.UserFields.TransmissionPower = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			vsBcaudEnable.UserFields.PcmSamplesPerFrame = Convert.ToUInt32(value, 16);
		}
	}
}
