using System.Text;

namespace QCRPG.TSL.BT.Packets;

public static class AdvertisingTypeInfo
{
	public static AdvertisingTypeEnum ValueToAdvertisingType(uint value)
	{
		switch (value)
		{
		case 0u:
			return AdvertisingTypeEnum.Connectable_and_scannable_undirected_advertising_ADV_IND;
		case 1u:
			return AdvertisingTypeEnum.Connectable_high_duty_cycle_directed_advertising_ADV_DIRECT_IND_high_duty_cycle;
		case 2u:
			return AdvertisingTypeEnum.Scannable_undirected_advertising_ADV_SCAN_IND;
		case 3u:
			return AdvertisingTypeEnum.Non_connectable_undirected_advertising_ADV_NONCONN_IND;
		case 4u:
			return AdvertisingTypeEnum.Connectable_low_duty_cycle_directed_advertising_ADV_DIRECT_IND_low_duty_cycle;
		default:
			if (value >= 5 && value <= 255)
			{
				return AdvertisingTypeEnum.Reserved_for_future_use;
			}
			return AdvertisingTypeEnum.InvalidAdvertisingTypeValue;
		}
	}

	public static uint AdvertisingTypeToValue(AdvertisingTypeEnum enumItem)
	{
		return enumItem switch
		{
			AdvertisingTypeEnum.Connectable_and_scannable_undirected_advertising_ADV_IND => 0u, 
			AdvertisingTypeEnum.Connectable_high_duty_cycle_directed_advertising_ADV_DIRECT_IND_high_duty_cycle => 1u, 
			AdvertisingTypeEnum.Scannable_undirected_advertising_ADV_SCAN_IND => 2u, 
			AdvertisingTypeEnum.Non_connectable_undirected_advertising_ADV_NONCONN_IND => 3u, 
			AdvertisingTypeEnum.Connectable_low_duty_cycle_directed_advertising_ADV_DIRECT_IND_low_duty_cycle => 4u, 
			AdvertisingTypeEnum.Reserved_for_future_use => 5u, 
			_ => uint.MaxValue, 
		};
	}

	public static string AdvertisingTypeToString(AdvertisingTypeEnum enumItem)
	{
		return enumItem switch
		{
			AdvertisingTypeEnum.Connectable_and_scannable_undirected_advertising_ADV_IND => "Connectable and scannable undirected advertising (ADV_IND) (default)", 
			AdvertisingTypeEnum.Connectable_high_duty_cycle_directed_advertising_ADV_DIRECT_IND_high_duty_cycle => "Connectable high duty cycle directed advertising (ADV_DIRECT_IND, high duty cycle)", 
			AdvertisingTypeEnum.Scannable_undirected_advertising_ADV_SCAN_IND => "Scannable undirected advertising (ADV_SCAN_IND)", 
			AdvertisingTypeEnum.Non_connectable_undirected_advertising_ADV_NONCONN_IND => "Non connectable undirected advertising (ADV_NONCONN_IND)", 
			AdvertisingTypeEnum.Connectable_low_duty_cycle_directed_advertising_ADV_DIRECT_IND_low_duty_cycle => "Connectable low duty cycle directed advertising (ADV_DIRECT_IND, low duty cycle)", 
			AdvertisingTypeEnum.Reserved_for_future_use => "Reserved for future use", 
			_ => "Invalid AdvertisingType Value", 
		};
	}

	public static string AdvertisingTypeToDescription()
	{
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.AppendLine("0x0 = Connectable and scannable undirected advertising (ADV_IND) (default)");
		stringBuilder.AppendLine("0x1 = Connectable high duty cycle directed advertising (ADV_DIRECT_IND, high duty cycle)");
		stringBuilder.AppendLine("0x2 = Scannable undirected advertising (ADV_SCAN_IND)");
		stringBuilder.AppendLine("0x3 = Non connectable undirected advertising (ADV_NONCONN_IND)");
		stringBuilder.AppendLine("0x4 = Connectable low duty cycle directed advertising (ADV_DIRECT_IND, low duty cycle)");
		stringBuilder.AppendLine("0x5-0xFF = Reserved for future use");
		return stringBuilder.ToString();
	}
}
