using System.Text;

namespace QCRPG.TSL.ZigBee.Packets;

public static class ErrorCodeInfo
{
	public static ErrorCodeEnum ValueToErrorCode(uint value)
	{
		return value switch
		{
			0u => ErrorCodeEnum.WPAN_STATUS_CODE_SUCCESS, 
			1u => ErrorCodeEnum.WPAN_ERROR_CONFIRM_CODE_COMMAND_NOT_SUPPORTED, 
			2u => ErrorCodeEnum.WPAN_ERROR_CONFIRM_CODE_INVALID_LENGTH, 
			3u => ErrorCodeEnum.WPAN_ERROR_CONFIRM_CODE_COMMAND_ERROR, 
			219u => ErrorCodeEnum.WPAN_STATUS_CODE_COUNTER_ERROR, 
			220u => ErrorCodeEnum.WPAN_STATUS_CODE_IMPROPER_KEY_TYPE, 
			221u => ErrorCodeEnum.WPAN_STATUS_CODE_IMPROPER_SECURITY_LEVEL, 
			222u => ErrorCodeEnum.WPAN_STATUS_CODE_UNSUPPORTED_LEGACY, 
			223u => ErrorCodeEnum.WPAN_STATUS_CODE_UNSUPPORTED_SECURITY, 
			224u => ErrorCodeEnum.WPAN_STATUS_CODE_BEACON_LOSS, 
			225u => ErrorCodeEnum.WPAN_STATUS_CODE_CHANNEL_ACCESS_FAILURE, 
			226u => ErrorCodeEnum.WPAN_STATUS_CODE_DENIED, 
			227u => ErrorCodeEnum.WPAN_STATUS_CODE_DISABLE_TRX_FAILURE, 
			228u => ErrorCodeEnum.WPAN_STATUS_CODE_SECURITY_ERROR, 
			229u => ErrorCodeEnum.WPAN_STATUS_CODE_FRAME_TOO_LONG, 
			230u => ErrorCodeEnum.WPAN_STATUS_CODE_INVALID_GTS, 
			231u => ErrorCodeEnum.WPAN_STATUS_CODE_INVALID_HANDLE, 
			232u => ErrorCodeEnum.WPAN_STATUS_CODE_INVALID_PARAMETER, 
			233u => ErrorCodeEnum.WPAN_STATUS_CODE_NO_ACK, 
			234u => ErrorCodeEnum.WPAN_STATUS_CODE_NO_BEACON, 
			235u => ErrorCodeEnum.WPAN_STATUS_CODE_NO_DATA, 
			236u => ErrorCodeEnum.WPAN_STATUS_CODE_NO_SHORT_ADDRESS, 
			237u => ErrorCodeEnum.WPAN_STATUS_CODE_OUT_OF_CAP, 
			238u => ErrorCodeEnum.WPAN_STATUS_CODE_PAN_ID_CONFLIC, 
			239u => ErrorCodeEnum.WPAN_STATUS_CODE_REALIGNMENT, 
			240u => ErrorCodeEnum.WPAN_STATUS_CODE_TRANSACTION_EXPIRED, 
			241u => ErrorCodeEnum.WPAN_STATUS_CODE_TRANSACTION_OVERFLOW, 
			242u => ErrorCodeEnum.WPAN_STATUS_CODE_TX_ACTIVE, 
			243u => ErrorCodeEnum.WPAN_STATUS_CODE_UNAVAILABLE_KEY, 
			244u => ErrorCodeEnum.WPAN_STATUS_CODE_UNSUPPORTED_ATTRIBUTE, 
			245u => ErrorCodeEnum.WPAN_STATUS_CODE_INVALID_ADDRESS, 
			246u => ErrorCodeEnum.WPAN_STATUS_CODE_ON_TIME_TOO_LONG, 
			247u => ErrorCodeEnum.WPAN_STATUS_CODE_PAST_TIME, 
			248u => ErrorCodeEnum.WPAN_STATUS_CODE_TRACKING_OFF, 
			249u => ErrorCodeEnum.WPAN_STATUS_CODE_INVALID_INDEX, 
			250u => ErrorCodeEnum.WPAN_STATUS_CODE_LIMIT_REACHED, 
			251u => ErrorCodeEnum.WPAN_STATUS_CODE_READ_ONLY, 
			252u => ErrorCodeEnum.WPAN_STATUS_CODE_SCAN_IN_PROGRESS, 
			253u => ErrorCodeEnum.WPAN_STATUS_CODE_SUPERFRAME_OVERLAP, 
			255u => ErrorCodeEnum.WPAN_STATUS_CODE_DEVICE_ERROR, 
			_ => ErrorCodeEnum.InvalidErrorCodeValue, 
		};
	}

	public static uint ErrorCodeToValue(ErrorCodeEnum enumItem)
	{
		return enumItem switch
		{
			ErrorCodeEnum.WPAN_STATUS_CODE_SUCCESS => 0u, 
			ErrorCodeEnum.WPAN_ERROR_CONFIRM_CODE_COMMAND_NOT_SUPPORTED => 1u, 
			ErrorCodeEnum.WPAN_ERROR_CONFIRM_CODE_INVALID_LENGTH => 2u, 
			ErrorCodeEnum.WPAN_ERROR_CONFIRM_CODE_COMMAND_ERROR => 3u, 
			ErrorCodeEnum.WPAN_STATUS_CODE_COUNTER_ERROR => 219u, 
			ErrorCodeEnum.WPAN_STATUS_CODE_IMPROPER_KEY_TYPE => 220u, 
			ErrorCodeEnum.WPAN_STATUS_CODE_IMPROPER_SECURITY_LEVEL => 221u, 
			ErrorCodeEnum.WPAN_STATUS_CODE_UNSUPPORTED_LEGACY => 222u, 
			ErrorCodeEnum.WPAN_STATUS_CODE_UNSUPPORTED_SECURITY => 223u, 
			ErrorCodeEnum.WPAN_STATUS_CODE_BEACON_LOSS => 224u, 
			ErrorCodeEnum.WPAN_STATUS_CODE_CHANNEL_ACCESS_FAILURE => 225u, 
			ErrorCodeEnum.WPAN_STATUS_CODE_DENIED => 226u, 
			ErrorCodeEnum.WPAN_STATUS_CODE_DISABLE_TRX_FAILURE => 227u, 
			ErrorCodeEnum.WPAN_STATUS_CODE_SECURITY_ERROR => 228u, 
			ErrorCodeEnum.WPAN_STATUS_CODE_FRAME_TOO_LONG => 229u, 
			ErrorCodeEnum.WPAN_STATUS_CODE_INVALID_GTS => 230u, 
			ErrorCodeEnum.WPAN_STATUS_CODE_INVALID_HANDLE => 231u, 
			ErrorCodeEnum.WPAN_STATUS_CODE_INVALID_PARAMETER => 232u, 
			ErrorCodeEnum.WPAN_STATUS_CODE_NO_ACK => 233u, 
			ErrorCodeEnum.WPAN_STATUS_CODE_NO_BEACON => 234u, 
			ErrorCodeEnum.WPAN_STATUS_CODE_NO_DATA => 235u, 
			ErrorCodeEnum.WPAN_STATUS_CODE_NO_SHORT_ADDRESS => 236u, 
			ErrorCodeEnum.WPAN_STATUS_CODE_OUT_OF_CAP => 237u, 
			ErrorCodeEnum.WPAN_STATUS_CODE_PAN_ID_CONFLIC => 238u, 
			ErrorCodeEnum.WPAN_STATUS_CODE_REALIGNMENT => 239u, 
			ErrorCodeEnum.WPAN_STATUS_CODE_TRANSACTION_EXPIRED => 240u, 
			ErrorCodeEnum.WPAN_STATUS_CODE_TRANSACTION_OVERFLOW => 241u, 
			ErrorCodeEnum.WPAN_STATUS_CODE_TX_ACTIVE => 242u, 
			ErrorCodeEnum.WPAN_STATUS_CODE_UNAVAILABLE_KEY => 243u, 
			ErrorCodeEnum.WPAN_STATUS_CODE_UNSUPPORTED_ATTRIBUTE => 244u, 
			ErrorCodeEnum.WPAN_STATUS_CODE_INVALID_ADDRESS => 245u, 
			ErrorCodeEnum.WPAN_STATUS_CODE_ON_TIME_TOO_LONG => 246u, 
			ErrorCodeEnum.WPAN_STATUS_CODE_PAST_TIME => 247u, 
			ErrorCodeEnum.WPAN_STATUS_CODE_TRACKING_OFF => 248u, 
			ErrorCodeEnum.WPAN_STATUS_CODE_INVALID_INDEX => 249u, 
			ErrorCodeEnum.WPAN_STATUS_CODE_LIMIT_REACHED => 250u, 
			ErrorCodeEnum.WPAN_STATUS_CODE_READ_ONLY => 251u, 
			ErrorCodeEnum.WPAN_STATUS_CODE_SCAN_IN_PROGRESS => 252u, 
			ErrorCodeEnum.WPAN_STATUS_CODE_SUPERFRAME_OVERLAP => 253u, 
			ErrorCodeEnum.WPAN_STATUS_CODE_DEVICE_ERROR => 255u, 
			_ => uint.MaxValue, 
		};
	}

	public static string ErrorCodeToString(ErrorCodeEnum enumItem)
	{
		return enumItem switch
		{
			ErrorCodeEnum.WPAN_STATUS_CODE_SUCCESS => "WPAN_STATUS_CODE_SUCCESS", 
			ErrorCodeEnum.WPAN_ERROR_CONFIRM_CODE_COMMAND_NOT_SUPPORTED => "WPAN_ERROR_CONFIRM_CODE_COMMAND_NOT_SUPPORTED", 
			ErrorCodeEnum.WPAN_ERROR_CONFIRM_CODE_INVALID_LENGTH => "WPAN_ERROR_CONFIRM_CODE_INVALID_LENGTH", 
			ErrorCodeEnum.WPAN_ERROR_CONFIRM_CODE_COMMAND_ERROR => "WPAN_ERROR_CONFIRM_CODE_COMMAND_ERROR", 
			ErrorCodeEnum.WPAN_STATUS_CODE_COUNTER_ERROR => "WPAN_STATUS_CODE_COUNTER_ERROR", 
			ErrorCodeEnum.WPAN_STATUS_CODE_IMPROPER_KEY_TYPE => "WPAN_STATUS_CODE_IMPROPER_KEY_TYPE", 
			ErrorCodeEnum.WPAN_STATUS_CODE_IMPROPER_SECURITY_LEVEL => "WPAN_STATUS_CODE_IMPROPER_SECURITY_LEVEL", 
			ErrorCodeEnum.WPAN_STATUS_CODE_UNSUPPORTED_LEGACY => "WPAN_STATUS_CODE_UNSUPPORTED_LEGACY", 
			ErrorCodeEnum.WPAN_STATUS_CODE_UNSUPPORTED_SECURITY => "WPAN_STATUS_CODE_UNSUPPORTED_SECURITY", 
			ErrorCodeEnum.WPAN_STATUS_CODE_BEACON_LOSS => "WPAN_STATUS_CODE_BEACON_LOSS", 
			ErrorCodeEnum.WPAN_STATUS_CODE_CHANNEL_ACCESS_FAILURE => "WPAN_STATUS_CODE_CHANNEL_ACCESS_FAILURE", 
			ErrorCodeEnum.WPAN_STATUS_CODE_DENIED => "WPAN_STATUS_CODE_DENIED", 
			ErrorCodeEnum.WPAN_STATUS_CODE_DISABLE_TRX_FAILURE => "WPAN_STATUS_CODE_DISABLE_TRX_FAILURE", 
			ErrorCodeEnum.WPAN_STATUS_CODE_SECURITY_ERROR => "WPAN_STATUS_CODE_SECURITY_ERROR", 
			ErrorCodeEnum.WPAN_STATUS_CODE_FRAME_TOO_LONG => "WPAN_STATUS_CODE_FRAME_TOO_LONG", 
			ErrorCodeEnum.WPAN_STATUS_CODE_INVALID_GTS => "WPAN_STATUS_CODE_INVALID_GTS", 
			ErrorCodeEnum.WPAN_STATUS_CODE_INVALID_HANDLE => "WPAN_STATUS_CODE_INVALID_HANDLE", 
			ErrorCodeEnum.WPAN_STATUS_CODE_INVALID_PARAMETER => "WPAN_STATUS_CODE_INVALID_PARAMETER", 
			ErrorCodeEnum.WPAN_STATUS_CODE_NO_ACK => "WPAN_STATUS_CODE_NO_ACK", 
			ErrorCodeEnum.WPAN_STATUS_CODE_NO_BEACON => "WPAN_STATUS_CODE_NO_BEACON", 
			ErrorCodeEnum.WPAN_STATUS_CODE_NO_DATA => "WPAN_STATUS_CODE_NO_DATA", 
			ErrorCodeEnum.WPAN_STATUS_CODE_NO_SHORT_ADDRESS => "WPAN_STATUS_CODE_NO_SHORT_ADDRESS", 
			ErrorCodeEnum.WPAN_STATUS_CODE_OUT_OF_CAP => "WPAN_STATUS_CODE_OUT_OF_CAP", 
			ErrorCodeEnum.WPAN_STATUS_CODE_PAN_ID_CONFLIC => "WPAN_STATUS_CODE_PAN_ID_CONFLIC", 
			ErrorCodeEnum.WPAN_STATUS_CODE_REALIGNMENT => "WPAN_STATUS_CODE_REALIGNMENT", 
			ErrorCodeEnum.WPAN_STATUS_CODE_TRANSACTION_EXPIRED => "WPAN_STATUS_CODE_TRANSACTION_EXPIRED", 
			ErrorCodeEnum.WPAN_STATUS_CODE_TRANSACTION_OVERFLOW => "WPAN_STATUS_CODE_TRANSACTION_OVERFLOW", 
			ErrorCodeEnum.WPAN_STATUS_CODE_TX_ACTIVE => "WPAN_STATUS_CODE_TX_ACTIVE", 
			ErrorCodeEnum.WPAN_STATUS_CODE_UNAVAILABLE_KEY => "WPAN_STATUS_CODE_UNAVAILABLE_KEY", 
			ErrorCodeEnum.WPAN_STATUS_CODE_UNSUPPORTED_ATTRIBUTE => "WPAN_STATUS_CODE_UNSUPPORTED_ATTRIBUTE", 
			ErrorCodeEnum.WPAN_STATUS_CODE_INVALID_ADDRESS => "WPAN_STATUS_CODE_INVALID_ADDRESS", 
			ErrorCodeEnum.WPAN_STATUS_CODE_ON_TIME_TOO_LONG => "WPAN_STATUS_CODE_ON_TIME_TOO_LONG", 
			ErrorCodeEnum.WPAN_STATUS_CODE_PAST_TIME => "WPAN_STATUS_CODE_PAST_TIME", 
			ErrorCodeEnum.WPAN_STATUS_CODE_TRACKING_OFF => "WPAN_STATUS_CODE_TRACKING_OFF", 
			ErrorCodeEnum.WPAN_STATUS_CODE_INVALID_INDEX => "WPAN_STATUS_CODE_INVALID_INDEX", 
			ErrorCodeEnum.WPAN_STATUS_CODE_LIMIT_REACHED => "WPAN_STATUS_CODE_LIMIT_REACHED", 
			ErrorCodeEnum.WPAN_STATUS_CODE_READ_ONLY => "WPAN_STATUS_CODE_READ_ONLY", 
			ErrorCodeEnum.WPAN_STATUS_CODE_SCAN_IN_PROGRESS => "WPAN_STATUS_CODE_SCAN_IN_PROGRESS", 
			ErrorCodeEnum.WPAN_STATUS_CODE_SUPERFRAME_OVERLAP => "WPAN_STATUS_CODE_SUPERFRAME_OVERLAP", 
			ErrorCodeEnum.WPAN_STATUS_CODE_DEVICE_ERROR => "WPAN_STATUS_CODE_DEVICE_ERROR", 
			_ => "Invalid ErrorCode Value", 
		};
	}

	public static string ErrorCodeToDescription()
	{
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.AppendLine("0x0 = WPAN_STATUS_CODE_SUCCESS");
		stringBuilder.AppendLine("0x1 = WPAN_ERROR_CONFIRM_CODE_COMMAND_NOT_SUPPORTED");
		stringBuilder.AppendLine("0x2 = WPAN_ERROR_CONFIRM_CODE_INVALID_LENGTH");
		stringBuilder.AppendLine("0x3 = WPAN_ERROR_CONFIRM_CODE_COMMAND_ERROR");
		stringBuilder.AppendLine("0xDB = WPAN_STATUS_CODE_COUNTER_ERROR");
		stringBuilder.AppendLine("0xDC = WPAN_STATUS_CODE_IMPROPER_KEY_TYPE");
		stringBuilder.AppendLine("0xDD = WPAN_STATUS_CODE_IMPROPER_SECURITY_LEVEL");
		stringBuilder.AppendLine("0xDE = WPAN_STATUS_CODE_UNSUPPORTED_LEGACY");
		stringBuilder.AppendLine("0xDF = WPAN_STATUS_CODE_UNSUPPORTED_SECURITY");
		stringBuilder.AppendLine("0xE0 = WPAN_STATUS_CODE_BEACON_LOSS");
		stringBuilder.AppendLine("0xE1 = WPAN_STATUS_CODE_CHANNEL_ACCESS_FAILURE");
		stringBuilder.AppendLine("0xE2 = WPAN_STATUS_CODE_DENIED");
		stringBuilder.AppendLine("0xE3 = WPAN_STATUS_CODE_DISABLE_TRX_FAILURE");
		stringBuilder.AppendLine("0xE4 = WPAN_STATUS_CODE_SECURITY_ERROR");
		stringBuilder.AppendLine("0xE5 = WPAN_STATUS_CODE_FRAME_TOO_LONG");
		stringBuilder.AppendLine("0xE6 = WPAN_STATUS_CODE_INVALID_GTS");
		stringBuilder.AppendLine("0xE7 = WPAN_STATUS_CODE_INVALID_HANDLE");
		stringBuilder.AppendLine("0xE8 = WPAN_STATUS_CODE_INVALID_PARAMETER");
		stringBuilder.AppendLine("0xE9 = WPAN_STATUS_CODE_NO_ACK");
		stringBuilder.AppendLine("0xEA = WPAN_STATUS_CODE_NO_BEACON");
		stringBuilder.AppendLine("0xEB = WPAN_STATUS_CODE_NO_DATA");
		stringBuilder.AppendLine("0xEC = WPAN_STATUS_CODE_NO_SHORT_ADDRESS");
		stringBuilder.AppendLine("0xED = WPAN_STATUS_CODE_OUT_OF_CAP");
		stringBuilder.AppendLine("0xEE = WPAN_STATUS_CODE_PAN_ID_CONFLIC");
		stringBuilder.AppendLine("0xEF = WPAN_STATUS_CODE_REALIGNMENT");
		stringBuilder.AppendLine("0xF0 = WPAN_STATUS_CODE_TRANSACTION_EXPIRED");
		stringBuilder.AppendLine("0xF1 = WPAN_STATUS_CODE_TRANSACTION_OVERFLOW");
		stringBuilder.AppendLine("0xF2 = WPAN_STATUS_CODE_TX_ACTIVE");
		stringBuilder.AppendLine("0xF3 = WPAN_STATUS_CODE_UNAVAILABLE_KEY");
		stringBuilder.AppendLine("0xF4 = WPAN_STATUS_CODE_UNSUPPORTED_ATTRIBUTE");
		stringBuilder.AppendLine("0xF5 = WPAN_STATUS_CODE_INVALID_ADDRESS");
		stringBuilder.AppendLine("0xF6 = WPAN_STATUS_CODE_ON_TIME_TOO_LONG");
		stringBuilder.AppendLine("0xF7 = WPAN_STATUS_CODE_PAST_TIME");
		stringBuilder.AppendLine("0xF8 = WPAN_STATUS_CODE_TRACKING_OFF");
		stringBuilder.AppendLine("0xF9 = WPAN_STATUS_CODE_INVALID_INDEX");
		stringBuilder.AppendLine("0xFA = WPAN_STATUS_CODE_LIMIT_REACHED");
		stringBuilder.AppendLine("0xFB = WPAN_STATUS_CODE_READ_ONLY");
		stringBuilder.AppendLine("0xFC = WPAN_STATUS_CODE_SCAN_IN_PROGRESS");
		stringBuilder.AppendLine("0xFD = WPAN_STATUS_CODE_SUPERFRAME_OVERLAP");
		stringBuilder.AppendLine("0xFF = WPAN_STATUS_CODE_DEVICE_ERROR");
		return stringBuilder.ToString();
	}
}
