using System.Text;

namespace QCRPG.TSL.BT.Packets;

public static class OwnAddressTypeInfo
{
	public static OwnAddressTypeEnum ValueToOwnAddressType(uint value)
	{
		switch (value)
		{
		case 0u:
			return OwnAddressTypeEnum.Public_Device_Address;
		case 1u:
			return OwnAddressTypeEnum.Random_Device_Address;
		case 2u:
			return OwnAddressTypeEnum.Resolvable_Private_Address_OR_Public_Address;
		case 3u:
			return OwnAddressTypeEnum.Resolvable_Private_Address_OR_LE_Set_Random_Address;
		default:
			if (value >= 4 && value <= 255)
			{
				return OwnAddressTypeEnum.Reserved_for_future_use;
			}
			return OwnAddressTypeEnum.InvalidOwnAddressTypeValue;
		}
	}

	public static uint OwnAddressTypeToValue(OwnAddressTypeEnum enumItem)
	{
		return enumItem switch
		{
			OwnAddressTypeEnum.Public_Device_Address => 0u, 
			OwnAddressTypeEnum.Random_Device_Address => 1u, 
			OwnAddressTypeEnum.Resolvable_Private_Address_OR_Public_Address => 2u, 
			OwnAddressTypeEnum.Resolvable_Private_Address_OR_LE_Set_Random_Address => 3u, 
			OwnAddressTypeEnum.Reserved_for_future_use => 4u, 
			_ => uint.MaxValue, 
		};
	}

	public static string OwnAddressTypeToString(OwnAddressTypeEnum enumItem)
	{
		return enumItem switch
		{
			OwnAddressTypeEnum.Public_Device_Address => "Public Device Address", 
			OwnAddressTypeEnum.Random_Device_Address => "Random Device Address", 
			OwnAddressTypeEnum.Resolvable_Private_Address_OR_Public_Address => "Controller generates Resolvable Private Address based on the local IRK from the resolving list. If the resolving list contains no matching entry, use the public address.", 
			OwnAddressTypeEnum.Resolvable_Private_Address_OR_LE_Set_Random_Address => "Controller generates Resolvable Private Address based on the local IRK from the resolving list. If the resolving list contains no matching entry, use the random address from LE_Set_Random_Address.", 
			OwnAddressTypeEnum.Reserved_for_future_use => "Reserved for future use", 
			_ => "Invalid OwnAddressType Value", 
		};
	}

	public static string OwnAddressTypeToDescription()
	{
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.AppendLine("0x0 = Public Device Address");
		stringBuilder.AppendLine("0x1 = Random Device Address");
		stringBuilder.AppendLine("0x2 = Controller generates Resolvable Private Address based on the local IRK from the resolving list. If the resolving list contains no matching entry, use the public address.");
		stringBuilder.AppendLine("0x3 = Controller generates Resolvable Private Address based on the local IRK from the resolving list. If the resolving list contains no matching entry, use the random address from LE_Set_Random_Address.");
		stringBuilder.AppendLine("0x4-0xFF = Reserved for future use");
		return stringBuilder.ToString();
	}
}
