using System.Text;

namespace QCRPG.TSL.BT.Packets;

public static class AciControlMapInfo
{
	public static AciControlMapEnumCollection ValueToAciControlMap(uint value)
	{
		AciControlMapEnumCollection aciControlMapEnumCollection = new AciControlMapEnumCollection();
		aciControlMapEnumCollection.FrameSyncType = AciControlMapEnumCollection.FrameSyncTypeInfo.ValueToFrameSyncType((value & 0xE) >> 1);
		aciControlMapEnumCollection.PcmRole = AciControlMapEnumCollection.PcmRoleInfo.ValueToPcmRole((value & 0x10) >> 4);
		aciControlMapEnumCollection.IntervalHardwareLoopback = EnableBitInfo.ValueToEnableBit((value & 0x20) >> 5);
		aciControlMapEnumCollection.InvertBclk = EnableBitInfo.ValueToEnableBit((value & 0x40) >> 6);
		return aciControlMapEnumCollection;
	}

	public static uint AciControlMapToValue(AciControlMapEnumCollection enumCollection)
	{
		uint num = 0u;
		num |= AciControlMapEnumCollection.FrameSyncTypeInfo.FrameSyncTypeToValue(enumCollection.FrameSyncType) << 1;
		num |= AciControlMapEnumCollection.PcmRoleInfo.PcmRoleToValue(enumCollection.PcmRole) << 4;
		num |= EnableBitInfo.EnableBitToValue(enumCollection.IntervalHardwareLoopback) << 5;
		return num | (EnableBitInfo.EnableBitToValue(enumCollection.InvertBclk) << 6);
	}

	public static string AciControlMapToString(AciControlMapEnumCollection enumCollection)
	{
		string text = "";
		text = text + "Frame Sync Type: " + AciControlMapEnumCollection.FrameSyncTypeInfo.FrameSyncTypeToString(enumCollection.FrameSyncType) + "\r\n";
		text = text + "PCM Role: " + AciControlMapEnumCollection.PcmRoleInfo.PcmRoleToString(enumCollection.PcmRole) + "\r\n";
		text = text + "Interval Hardware Loopback: " + EnableBitInfo.EnableBitToString(enumCollection.IntervalHardwareLoopback) + "\r\n";
		text = text + "Invert BCLK: " + EnableBitInfo.EnableBitToString(enumCollection.InvertBclk) + "\r\n";
		return text.TrimEnd('\r', '\n');
	}

	public static string AciControlMapToDescription()
	{
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.AppendLine("Bit 0: Reserved");
		stringBuilder.AppendLine("Bits 3-1: Frame Sync Type");
		stringBuilder.AppendLine(AciControlMapEnumCollection.FrameSyncTypeInfo.FrameSyncTypeToDescription());
		stringBuilder.AppendLine("Bit 4: PCM Role");
		stringBuilder.AppendLine(AciControlMapEnumCollection.PcmRoleInfo.PcmRoleToDescription());
		stringBuilder.AppendLine("Bit 5: Interval Hardware Loopback");
		stringBuilder.AppendLine("Bit 6: Invert BCLK");
		stringBuilder.AppendLine("Bit 7: Reserved");
		return stringBuilder.ToString();
	}
}
