using System.Text;

namespace QCRPG.TSL.BT.Packets;

public static class AclPacketTypeInfo
{
	public static AclPacketTypeEnumCollection ValueToAclPacketType(uint value)
	{
		AclPacketTypeEnumCollection aclPacketTypeEnumCollection = new AclPacketTypeEnumCollection();
		aclPacketTypeEnumCollection.TwoDh1MayNotBeUsed = AssertBitInfo.ValueToAssertBit((value & 2) >> 1);
		aclPacketTypeEnumCollection.ThreeDh1MayNotBeUsed = AssertBitInfo.ValueToAssertBit((value & 4) >> 2);
		aclPacketTypeEnumCollection.Dm1MayBeUsed = AssertBitInfo.ValueToAssertBit((value & 8) >> 3);
		aclPacketTypeEnumCollection.Dh1MayBeUsed = AssertBitInfo.ValueToAssertBit((value & 0x10) >> 4);
		aclPacketTypeEnumCollection.TwoDh3MayNotBeUsed = AssertBitInfo.ValueToAssertBit((value & 0x100) >> 8);
		aclPacketTypeEnumCollection.ThreeDh3MayNotBeUsed = AssertBitInfo.ValueToAssertBit((value & 0x200) >> 9);
		aclPacketTypeEnumCollection.Dm3MayBeUsed = AssertBitInfo.ValueToAssertBit((value & 0x400) >> 10);
		aclPacketTypeEnumCollection.Dh3MayBeUsed = AssertBitInfo.ValueToAssertBit((value & 0x800) >> 11);
		aclPacketTypeEnumCollection.TwoDh5MayNotBeUsed = AssertBitInfo.ValueToAssertBit((value & 0x1000) >> 12);
		aclPacketTypeEnumCollection.ThreeDh5MayNotBeUsed = AssertBitInfo.ValueToAssertBit((value & 0x2000) >> 13);
		aclPacketTypeEnumCollection.Dm5MayBeUsed = AssertBitInfo.ValueToAssertBit((value & 0x4000) >> 14);
		aclPacketTypeEnumCollection.Dh5MayBeUsed = AssertBitInfo.ValueToAssertBit((value & 0x8000) >> 15);
		return aclPacketTypeEnumCollection;
	}

	public static uint AclPacketTypeToValue(AclPacketTypeEnumCollection enumCollection)
	{
		uint num = 0u;
		num |= AssertBitInfo.AssertBitToValue(enumCollection.TwoDh1MayNotBeUsed) << 1;
		num |= AssertBitInfo.AssertBitToValue(enumCollection.ThreeDh1MayNotBeUsed) << 2;
		num |= AssertBitInfo.AssertBitToValue(enumCollection.Dm1MayBeUsed) << 3;
		num |= AssertBitInfo.AssertBitToValue(enumCollection.Dh1MayBeUsed) << 4;
		num |= AssertBitInfo.AssertBitToValue(enumCollection.TwoDh3MayNotBeUsed) << 8;
		num |= AssertBitInfo.AssertBitToValue(enumCollection.ThreeDh3MayNotBeUsed) << 9;
		num |= AssertBitInfo.AssertBitToValue(enumCollection.Dm3MayBeUsed) << 10;
		num |= AssertBitInfo.AssertBitToValue(enumCollection.Dh3MayBeUsed) << 11;
		num |= AssertBitInfo.AssertBitToValue(enumCollection.TwoDh5MayNotBeUsed) << 12;
		num |= AssertBitInfo.AssertBitToValue(enumCollection.ThreeDh5MayNotBeUsed) << 13;
		num |= AssertBitInfo.AssertBitToValue(enumCollection.Dm5MayBeUsed) << 14;
		return num | (AssertBitInfo.AssertBitToValue(enumCollection.Dh5MayBeUsed) << 15);
	}

	public static string AclPacketTypeToString(AclPacketTypeEnumCollection enumCollection)
	{
		string text = "";
		text = text + "Two-DH1 may not be used: " + AssertBitInfo.AssertBitToString(enumCollection.TwoDh1MayNotBeUsed) + "\r\n";
		text = text + "Three-DH1 may not be used: " + AssertBitInfo.AssertBitToString(enumCollection.ThreeDh1MayNotBeUsed) + "\r\n";
		text = text + "DM1 may be used: " + AssertBitInfo.AssertBitToString(enumCollection.Dm1MayBeUsed) + "\r\n";
		text = text + "DH1 may be used: " + AssertBitInfo.AssertBitToString(enumCollection.Dh1MayBeUsed) + "\r\n";
		text = text + "Two-DH3 may not be used: " + AssertBitInfo.AssertBitToString(enumCollection.TwoDh3MayNotBeUsed) + "\r\n";
		text = text + "Three-DH3 may not be used: " + AssertBitInfo.AssertBitToString(enumCollection.ThreeDh3MayNotBeUsed) + "\r\n";
		text = text + "DM3 may be used: " + AssertBitInfo.AssertBitToString(enumCollection.Dm3MayBeUsed) + "\r\n";
		text = text + "DH3 may be used: " + AssertBitInfo.AssertBitToString(enumCollection.Dh3MayBeUsed) + "\r\n";
		text = text + "Two-DH5 may not be used: " + AssertBitInfo.AssertBitToString(enumCollection.TwoDh5MayNotBeUsed) + "\r\n";
		text = text + "Three-DH5 may not be used: " + AssertBitInfo.AssertBitToString(enumCollection.ThreeDh5MayNotBeUsed) + "\r\n";
		text = text + "DM5 may be used: " + AssertBitInfo.AssertBitToString(enumCollection.Dm5MayBeUsed) + "\r\n";
		text = text + "DH5 may be used: " + AssertBitInfo.AssertBitToString(enumCollection.Dh5MayBeUsed) + "\r\n";
		return text.TrimEnd('\r', '\n');
	}

	public static string AclPacketTypeToDescription()
	{
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.AppendLine("Bit 0: Reserved for future use");
		stringBuilder.AppendLine("Bit 1: Two-DH1 may not be used");
		stringBuilder.AppendLine(AssertBitInfo.AssertBitToDescription());
		stringBuilder.AppendLine("Bit 2: Three-DH1 may not be used");
		stringBuilder.AppendLine(AssertBitInfo.AssertBitToDescription());
		stringBuilder.AppendLine("Bit 3: DM1 may be used");
		stringBuilder.AppendLine(AssertBitInfo.AssertBitToDescription());
		stringBuilder.AppendLine("Bit 4: DH1 may be used");
		stringBuilder.AppendLine(AssertBitInfo.AssertBitToDescription());
		stringBuilder.AppendLine("Bits 7-5: Reserved for future use");
		stringBuilder.AppendLine("Bit 8: Two-DH3 may not be used");
		stringBuilder.AppendLine(AssertBitInfo.AssertBitToDescription());
		stringBuilder.AppendLine("Bit 9: Three-DH3 may not be used");
		stringBuilder.AppendLine(AssertBitInfo.AssertBitToDescription());
		stringBuilder.AppendLine("Bit 10: DM3 may be used");
		stringBuilder.AppendLine(AssertBitInfo.AssertBitToDescription());
		stringBuilder.AppendLine("Bit 11: DH3 may be used");
		stringBuilder.AppendLine(AssertBitInfo.AssertBitToDescription());
		stringBuilder.AppendLine("Bit 12: Two-DH5 may not be used");
		stringBuilder.AppendLine(AssertBitInfo.AssertBitToDescription());
		stringBuilder.AppendLine("Bit 13: Three-DH5 may not be used");
		stringBuilder.AppendLine(AssertBitInfo.AssertBitToDescription());
		stringBuilder.AppendLine("Bit 14: DM5 may be used");
		stringBuilder.AppendLine(AssertBitInfo.AssertBitToDescription());
		stringBuilder.AppendLine("Bit 15: DH5 may be used");
		stringBuilder.AppendLine(AssertBitInfo.AssertBitToDescription());
		return stringBuilder.ToString();
	}
}
