using System.Text;

namespace QCRPG.TSL.BT.Packets;

public static class ScanningFilterPolicyInfo
{
	public static ScanningFilterPolicyEnum ValueToScanningFilterPolicy(uint value)
	{
		switch (value)
		{
		case 0u:
			return ScanningFilterPolicyEnum.Accept_all_except_directed;
		case 1u:
			return ScanningFilterPolicyEnum.Accept_only;
		case 2u:
			return ScanningFilterPolicyEnum.Accept_all_undirected;
		case 3u:
			return ScanningFilterPolicyEnum.Accept_all_advertising_WhiteList;
		default:
			if (value >= 4 && value <= 255)
			{
				return ScanningFilterPolicyEnum.Reserved_for_future_use;
			}
			return ScanningFilterPolicyEnum.InvalidScanningFilterPolicyValue;
		}
	}

	public static uint ScanningFilterPolicyToValue(ScanningFilterPolicyEnum enumItem)
	{
		return enumItem switch
		{
			ScanningFilterPolicyEnum.Accept_all_except_directed => 0u, 
			ScanningFilterPolicyEnum.Accept_only => 1u, 
			ScanningFilterPolicyEnum.Accept_all_undirected => 2u, 
			ScanningFilterPolicyEnum.Accept_all_advertising_WhiteList => 3u, 
			ScanningFilterPolicyEnum.Reserved_for_future_use => 4u, 
			_ => uint.MaxValue, 
		};
	}

	public static string ScanningFilterPolicyToString(ScanningFilterPolicyEnum enumItem)
	{
		return enumItem switch
		{
			ScanningFilterPolicyEnum.Accept_all_except_directed => "Accept all advertising packets except directed advertising packets not addressed to this device (default).", 
			ScanningFilterPolicyEnum.Accept_only => "Accept only advertising packets from devices where the advertiser's address is in the White list. Directed advertising packets which are not addressed to this device shall be ignored.", 
			ScanningFilterPolicyEnum.Accept_all_undirected => "Accept all advertising packets except directed advertising packets where the initiator's identity address does not address this device. Note: Directed advertising packets where the initiator's address is a resolvable private address that cannot be resolved are also accepted.", 
			ScanningFilterPolicyEnum.Accept_all_advertising_WhiteList => "Accept all advertising packets except: • advertising packets where the advertiser's identity address is not in the White List; and • directed advertising packets where the initiator's identity address does not address this device. Note: Directed advertising packets where the initiator's address is a resolvable private address that cannot be resolved are also accepted.", 
			ScanningFilterPolicyEnum.Reserved_for_future_use => "Reserved for future use", 
			_ => "Invalid ScanningFilterPolicy Value", 
		};
	}

	public static string ScanningFilterPolicyToDescription()
	{
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.AppendLine("0x0 = Accept all advertising packets except directed advertising packets not addressed to this device (default).");
		stringBuilder.AppendLine("0x1 = Accept only advertising packets from devices where the advertiser's address is in the White list. Directed advertising packets which are not addressed to this device shall be ignored.");
		stringBuilder.AppendLine("0x2 = Accept all advertising packets except directed advertising packets where the initiator's identity address does not address this device. Note: Directed advertising packets where the initiator's address is a resolvable private address that cannot be resolved are also accepted.");
		stringBuilder.AppendLine("0x3 = Accept all advertising packets except: • advertising packets where the advertiser's identity address is not in the White List; and • directed advertising packets where the initiator's identity address does not address this device. Note: Directed advertising packets where the initiator's address is a resolvable private address that cannot be resolved are also accepted.");
		stringBuilder.AppendLine("0x4-0xFF = Reserved for future use");
		return stringBuilder.ToString();
	}
}
