using System.Text;

namespace QCRPG.TSL.ZigBee.Packets;

public static class AssociationStatusInfo
{
	public static AssociationStatusEnum ValueToAssociationStatus(uint value)
	{
		switch (value)
		{
		case 0u:
			return AssociationStatusEnum.Association_Successful;
		case 1u:
			return AssociationStatusEnum.PAN_AT_CAPACITY;
		case 2u:
			return AssociationStatusEnum.PAN_ACCESS_DENIED;
		default:
			if (value >= 3 && value <= 255)
			{
				return AssociationStatusEnum.RESERVED;
			}
			return AssociationStatusEnum.InvalidAssociationStatusValue;
		}
	}

	public static uint AssociationStatusToValue(AssociationStatusEnum enumItem)
	{
		return enumItem switch
		{
			AssociationStatusEnum.Association_Successful => 0u, 
			AssociationStatusEnum.PAN_AT_CAPACITY => 1u, 
			AssociationStatusEnum.PAN_ACCESS_DENIED => 2u, 
			AssociationStatusEnum.RESERVED => 3u, 
			_ => uint.MaxValue, 
		};
	}

	public static string AssociationStatusToString(AssociationStatusEnum enumItem)
	{
		return enumItem switch
		{
			AssociationStatusEnum.Association_Successful => "Association_Successful", 
			AssociationStatusEnum.PAN_AT_CAPACITY => "PAN_AT_CAPACITY", 
			AssociationStatusEnum.PAN_ACCESS_DENIED => "PAN_ACCESS_DENIED", 
			AssociationStatusEnum.RESERVED => "Reserved", 
			_ => "Invalid AssociationStatus Value", 
		};
	}

	public static string AssociationStatusToDescription()
	{
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.AppendLine("0x0 = Association_Successful");
		stringBuilder.AppendLine("0x1 = PAN_AT_CAPACITY");
		stringBuilder.AppendLine("0x2 = PAN_ACCESS_DENIED");
		stringBuilder.AppendLine("0x3-0xFF = Reserved");
		return stringBuilder.ToString();
	}
}
