using System.Text;

namespace QCRPG.TSL.NFC.Packets;

public static class NfcbDataExchangeConfigurationInfo
{
	public static NfcbDataExchangeConfigurationEnumCollection ValueToNfcbDataExchangeConfiguration(uint value)
	{
		NfcbDataExchangeConfigurationEnumCollection nfcbDataExchangeConfigurationEnumCollection = new NfcbDataExchangeConfigurationEnumCollection();
		nfcbDataExchangeConfigurationEnumCollection.MinimumTr2 = NfcbDataExchangeConfigurationEnumCollection.MinimumTr2Info.ValueToMinimumTr2(value & 3u);
		nfcbDataExchangeConfigurationEnumCollection.SuppressionOfSos = SuppressionBitInfo.ValueToSuppressionBit((value & 4) >> 2);
		nfcbDataExchangeConfigurationEnumCollection.SuppressionOfEos = SuppressionBitInfo.ValueToSuppressionBit((value & 8) >> 3);
		nfcbDataExchangeConfigurationEnumCollection.MinimumTr1 = NfcbDataExchangeConfigurationEnumCollection.MinimumTr1Info.ValueToMinimumTr1((value & 0x30) >> 4);
		nfcbDataExchangeConfigurationEnumCollection.MinimumTr0 = NfcbDataExchangeConfigurationEnumCollection.MinimumTr0Info.ValueToMinimumTr0((value & 0xC0) >> 6);
		return nfcbDataExchangeConfigurationEnumCollection;
	}

	public static uint NfcbDataExchangeConfigurationToValue(NfcbDataExchangeConfigurationEnumCollection enumCollection)
	{
		uint num = 0u;
		num |= NfcbDataExchangeConfigurationEnumCollection.MinimumTr2Info.MinimumTr2ToValue(enumCollection.MinimumTr2);
		num |= SuppressionBitInfo.SuppressionBitToValue(enumCollection.SuppressionOfSos) << 2;
		num |= SuppressionBitInfo.SuppressionBitToValue(enumCollection.SuppressionOfEos) << 3;
		num |= NfcbDataExchangeConfigurationEnumCollection.MinimumTr1Info.MinimumTr1ToValue(enumCollection.MinimumTr1) << 4;
		return num | (NfcbDataExchangeConfigurationEnumCollection.MinimumTr0Info.MinimumTr0ToValue(enumCollection.MinimumTr0) << 6);
	}

	public static string NfcbDataExchangeConfigurationToString(NfcbDataExchangeConfigurationEnumCollection enumCollection)
	{
		string text = "";
		text = text + "Minimum TR2: " + NfcbDataExchangeConfigurationEnumCollection.MinimumTr2Info.MinimumTr2ToString(enumCollection.MinimumTr2) + "\r\n";
		text = text + "Suppression of SoS: " + SuppressionBitInfo.SuppressionBitToString(enumCollection.SuppressionOfSos) + "\r\n";
		text = text + "Suppression of EoS: " + SuppressionBitInfo.SuppressionBitToString(enumCollection.SuppressionOfEos) + "\r\n";
		text = text + "Minimum TR1: " + NfcbDataExchangeConfigurationEnumCollection.MinimumTr1Info.MinimumTr1ToString(enumCollection.MinimumTr1) + "\r\n";
		text = text + "Minimum TR0: " + NfcbDataExchangeConfigurationEnumCollection.MinimumTr0Info.MinimumTr0ToString(enumCollection.MinimumTr0) + "\r\n";
		return text.TrimEnd('\r', '\n');
	}

	public static string NfcbDataExchangeConfigurationToDescription()
	{
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.AppendLine("Bits 1-0: Minimum TR2");
		stringBuilder.AppendLine(NfcbDataExchangeConfigurationEnumCollection.MinimumTr2Info.MinimumTr2ToDescription());
		stringBuilder.AppendLine("Bit 2: Suppression of SoS");
		stringBuilder.AppendLine(SuppressionBitInfo.SuppressionBitToDescription());
		stringBuilder.AppendLine("Bit 3: Suppression of EoS");
		stringBuilder.AppendLine(SuppressionBitInfo.SuppressionBitToDescription());
		stringBuilder.AppendLine("Bits 5-4: Minimum TR1");
		stringBuilder.AppendLine(NfcbDataExchangeConfigurationEnumCollection.MinimumTr1Info.MinimumTr1ToDescription());
		stringBuilder.AppendLine("Bits 7-6: Minimum TR0");
		stringBuilder.AppendLine(NfcbDataExchangeConfigurationEnumCollection.MinimumTr0Info.MinimumTr0ToDescription());
		return stringBuilder.ToString();
	}
}
