using System.Text;

namespace QCRPG.TSL.BT.Packets;

public static class EnhancedSynchronousPacketTypeInfo
{
	public static EnhancedSynchronousPacketTypeEnumCollection ValueToEnhancedSynchronousPacketType(uint value)
	{
		EnhancedSynchronousPacketTypeEnumCollection enhancedSynchronousPacketTypeEnumCollection = new EnhancedSynchronousPacketTypeEnumCollection();
		enhancedSynchronousPacketTypeEnumCollection.Hv1MayBeUsed = AssertBitInfo.ValueToAssertBit(value & 1u);
		enhancedSynchronousPacketTypeEnumCollection.Hv2MayBeUsed = AssertBitInfo.ValueToAssertBit((value & 2) >> 1);
		enhancedSynchronousPacketTypeEnumCollection.Hv3MayBeUsed = AssertBitInfo.ValueToAssertBit((value & 4) >> 2);
		enhancedSynchronousPacketTypeEnumCollection.Ev3MayBeUsed = AssertBitInfo.ValueToAssertBit((value & 8) >> 3);
		enhancedSynchronousPacketTypeEnumCollection.Ev4MayBeUsed = AssertBitInfo.ValueToAssertBit((value & 0x10) >> 4);
		enhancedSynchronousPacketTypeEnumCollection.Ev5MayBeUsed = AssertBitInfo.ValueToAssertBit((value & 0x20) >> 5);
		enhancedSynchronousPacketTypeEnumCollection.TwoEv3ShallNotBeUsed = AssertBitInfo.ValueToAssertBit((value & 0x40) >> 6);
		enhancedSynchronousPacketTypeEnumCollection.ThreeEv3ShallNotBeUsed = AssertBitInfo.ValueToAssertBit((value & 0x80) >> 7);
		enhancedSynchronousPacketTypeEnumCollection.TwoEv5ShallNotBeUsed = AssertBitInfo.ValueToAssertBit((value & 0x100) >> 8);
		enhancedSynchronousPacketTypeEnumCollection.ThreeEv5ShallNotBeUsed = AssertBitInfo.ValueToAssertBit((value & 0x200) >> 9);
		return enhancedSynchronousPacketTypeEnumCollection;
	}

	public static uint EnhancedSynchronousPacketTypeToValue(EnhancedSynchronousPacketTypeEnumCollection enumCollection)
	{
		uint num = 0u;
		num |= AssertBitInfo.AssertBitToValue(enumCollection.Hv1MayBeUsed);
		num |= AssertBitInfo.AssertBitToValue(enumCollection.Hv2MayBeUsed) << 1;
		num |= AssertBitInfo.AssertBitToValue(enumCollection.Hv3MayBeUsed) << 2;
		num |= AssertBitInfo.AssertBitToValue(enumCollection.Ev3MayBeUsed) << 3;
		num |= AssertBitInfo.AssertBitToValue(enumCollection.Ev4MayBeUsed) << 4;
		num |= AssertBitInfo.AssertBitToValue(enumCollection.Ev5MayBeUsed) << 5;
		num |= AssertBitInfo.AssertBitToValue(enumCollection.TwoEv3ShallNotBeUsed) << 6;
		num |= AssertBitInfo.AssertBitToValue(enumCollection.ThreeEv3ShallNotBeUsed) << 7;
		num |= AssertBitInfo.AssertBitToValue(enumCollection.TwoEv5ShallNotBeUsed) << 8;
		return num | (AssertBitInfo.AssertBitToValue(enumCollection.ThreeEv5ShallNotBeUsed) << 9);
	}

	public static string EnhancedSynchronousPacketTypeToString(EnhancedSynchronousPacketTypeEnumCollection enumCollection)
	{
		string text = "";
		text = text + "HV1 may be used: " + AssertBitInfo.AssertBitToString(enumCollection.Hv1MayBeUsed) + "\r\n";
		text = text + "HV2 may be used: " + AssertBitInfo.AssertBitToString(enumCollection.Hv2MayBeUsed) + "\r\n";
		text = text + "HV3 may be used: " + AssertBitInfo.AssertBitToString(enumCollection.Hv3MayBeUsed) + "\r\n";
		text = text + "EV3 may be used: " + AssertBitInfo.AssertBitToString(enumCollection.Ev3MayBeUsed) + "\r\n";
		text = text + "EV4 may be used: " + AssertBitInfo.AssertBitToString(enumCollection.Ev4MayBeUsed) + "\r\n";
		text = text + "EV5 may be used: " + AssertBitInfo.AssertBitToString(enumCollection.Ev5MayBeUsed) + "\r\n";
		text = text + "Two-EV3 shall not be used: " + AssertBitInfo.AssertBitToString(enumCollection.TwoEv3ShallNotBeUsed) + "\r\n";
		text = text + "Three-EV3 shall not be used: " + AssertBitInfo.AssertBitToString(enumCollection.ThreeEv3ShallNotBeUsed) + "\r\n";
		text = text + "Two-EV5 shall not be used: " + AssertBitInfo.AssertBitToString(enumCollection.TwoEv5ShallNotBeUsed) + "\r\n";
		text = text + "Three-EV5 shall not be used: " + AssertBitInfo.AssertBitToString(enumCollection.ThreeEv5ShallNotBeUsed) + "\r\n";
		return text.TrimEnd('\r', '\n');
	}

	public static string EnhancedSynchronousPacketTypeToDescription()
	{
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.AppendLine("Bit 0: HV1 may be used");
		stringBuilder.AppendLine(AssertBitInfo.AssertBitToDescription());
		stringBuilder.AppendLine("Bit 1: HV2 may be used");
		stringBuilder.AppendLine(AssertBitInfo.AssertBitToDescription());
		stringBuilder.AppendLine("Bit 2: HV3 may be used");
		stringBuilder.AppendLine(AssertBitInfo.AssertBitToDescription());
		stringBuilder.AppendLine("Bit 3: EV3 may be used");
		stringBuilder.AppendLine(AssertBitInfo.AssertBitToDescription());
		stringBuilder.AppendLine("Bit 4: EV4 may be used");
		stringBuilder.AppendLine(AssertBitInfo.AssertBitToDescription());
		stringBuilder.AppendLine("Bit 5: EV5 may be used");
		stringBuilder.AppendLine(AssertBitInfo.AssertBitToDescription());
		stringBuilder.AppendLine("Bit 6: Two-EV3 shall not be used");
		stringBuilder.AppendLine(AssertBitInfo.AssertBitToDescription());
		stringBuilder.AppendLine("Bit 7: Three-EV3 shall not be used");
		stringBuilder.AppendLine(AssertBitInfo.AssertBitToDescription());
		stringBuilder.AppendLine("Bit 8: Two-EV5 shall not be used");
		stringBuilder.AppendLine(AssertBitInfo.AssertBitToDescription());
		stringBuilder.AppendLine("Bit 9: Three-EV5 shall not be used");
		stringBuilder.AppendLine(AssertBitInfo.AssertBitToDescription());
		stringBuilder.AppendLine("Bits 15-10: Reserved for future use");
		return stringBuilder.ToString();
	}
}
