using System.Text;

namespace QCRPG.TSL.ZigBee.Packets;

public static class CommandOpcodeInfo
{
	public static CommandOpcodeEnum ValueToCommandOpcode(uint value)
	{
		return value switch
		{
			1u => CommandOpcodeEnum.MCPS_DATA_REQUEST, 
			2u => CommandOpcodeEnum.MCPS_DATA_PURGE, 
			32u => CommandOpcodeEnum.MLME_ASSOCIATE, 
			33u => CommandOpcodeEnum.MLME_DISASSOCIATE, 
			34u => CommandOpcodeEnum.MLME_BEACON_NOTIFY, 
			35u => CommandOpcodeEnum.MLME_GET, 
			36u => CommandOpcodeEnum.MLME_GTS, 
			37u => CommandOpcodeEnum.MLME_ORPHAN, 
			38u => CommandOpcodeEnum.MLME_RESET, 
			39u => CommandOpcodeEnum.MLME_RX_ENABLE, 
			40u => CommandOpcodeEnum.MLME_SCAN, 
			41u => CommandOpcodeEnum.MLME_COMM_STATUS, 
			42u => CommandOpcodeEnum.MLME_SET, 
			43u => CommandOpcodeEnum.MLME_START, 
			44u => CommandOpcodeEnum.MLME_SYNC, 
			45u => CommandOpcodeEnum.MLME_SYNC_LOSS, 
			46u => CommandOpcodeEnum.MLME_POLL, 
			128u => CommandOpcodeEnum.VS_DUT_ENABLE, 
			129u => CommandOpcodeEnum.VS_DUT_TX_TEST, 
			130u => CommandOpcodeEnum.VS_DUT_RX_TEST, 
			131u => CommandOpcodeEnum.VS_DUT_RX_STAT, 
			132u => CommandOpcodeEnum.VS_DUT_RX_RSSI, 
			133u => CommandOpcodeEnum.VS_DUT_END_TEST, 
			134u => CommandOpcodeEnum.VS_PEEK, 
			135u => CommandOpcodeEnum.VS_POKE, 
			136u => CommandOpcodeEnum.VS_NVM_GET, 
			137u => CommandOpcodeEnum.VS_NVM_SET, 
			138u => CommandOpcodeEnum.VS_WHITELIST, 
			139u => CommandOpcodeEnum.VS_DUT_TX_RAW, 
			140u => CommandOpcodeEnum.VS_DUT_CCA_SCAN, 
			255u => CommandOpcodeEnum.COMMAND_ERROR, 
			_ => CommandOpcodeEnum.InvalidCommandOpcodeValue, 
		};
	}

	public static uint CommandOpcodeToValue(CommandOpcodeEnum enumItem)
	{
		return enumItem switch
		{
			CommandOpcodeEnum.MCPS_DATA_REQUEST => 1u, 
			CommandOpcodeEnum.MCPS_DATA_PURGE => 2u, 
			CommandOpcodeEnum.MLME_ASSOCIATE => 32u, 
			CommandOpcodeEnum.MLME_DISASSOCIATE => 33u, 
			CommandOpcodeEnum.MLME_BEACON_NOTIFY => 34u, 
			CommandOpcodeEnum.MLME_GET => 35u, 
			CommandOpcodeEnum.MLME_GTS => 36u, 
			CommandOpcodeEnum.MLME_ORPHAN => 37u, 
			CommandOpcodeEnum.MLME_RESET => 38u, 
			CommandOpcodeEnum.MLME_RX_ENABLE => 39u, 
			CommandOpcodeEnum.MLME_SCAN => 40u, 
			CommandOpcodeEnum.MLME_COMM_STATUS => 41u, 
			CommandOpcodeEnum.MLME_SET => 42u, 
			CommandOpcodeEnum.MLME_START => 43u, 
			CommandOpcodeEnum.MLME_SYNC => 44u, 
			CommandOpcodeEnum.MLME_SYNC_LOSS => 45u, 
			CommandOpcodeEnum.MLME_POLL => 46u, 
			CommandOpcodeEnum.VS_DUT_ENABLE => 128u, 
			CommandOpcodeEnum.VS_DUT_TX_TEST => 129u, 
			CommandOpcodeEnum.VS_DUT_RX_TEST => 130u, 
			CommandOpcodeEnum.VS_DUT_RX_STAT => 131u, 
			CommandOpcodeEnum.VS_DUT_RX_RSSI => 132u, 
			CommandOpcodeEnum.VS_DUT_END_TEST => 133u, 
			CommandOpcodeEnum.VS_PEEK => 134u, 
			CommandOpcodeEnum.VS_POKE => 135u, 
			CommandOpcodeEnum.VS_NVM_GET => 136u, 
			CommandOpcodeEnum.VS_NVM_SET => 137u, 
			CommandOpcodeEnum.VS_WHITELIST => 138u, 
			CommandOpcodeEnum.VS_DUT_TX_RAW => 139u, 
			CommandOpcodeEnum.VS_DUT_CCA_SCAN => 140u, 
			CommandOpcodeEnum.COMMAND_ERROR => 255u, 
			_ => uint.MaxValue, 
		};
	}

	public static string CommandOpcodeToString(CommandOpcodeEnum enumItem)
	{
		return enumItem switch
		{
			CommandOpcodeEnum.MCPS_DATA_REQUEST => "MCPS_DATA_REQUEST", 
			CommandOpcodeEnum.MCPS_DATA_PURGE => "MCPS_DATA_PURGE", 
			CommandOpcodeEnum.MLME_ASSOCIATE => "MLME_ASSOCIATE", 
			CommandOpcodeEnum.MLME_DISASSOCIATE => "MLME_DISASSOCIATE", 
			CommandOpcodeEnum.MLME_BEACON_NOTIFY => "MLME_BEACON_NOTIFY", 
			CommandOpcodeEnum.MLME_GET => "MLME_GET", 
			CommandOpcodeEnum.MLME_GTS => "MLME_GTS", 
			CommandOpcodeEnum.MLME_ORPHAN => "MLME_ORPHAN", 
			CommandOpcodeEnum.MLME_RESET => "MLME_RESET", 
			CommandOpcodeEnum.MLME_RX_ENABLE => "MLME_RX_ENABLE", 
			CommandOpcodeEnum.MLME_SCAN => "MLME_SCAN", 
			CommandOpcodeEnum.MLME_COMM_STATUS => "MLME_COMM_STATUS", 
			CommandOpcodeEnum.MLME_SET => "MLME_SET", 
			CommandOpcodeEnum.MLME_START => "MLME_START", 
			CommandOpcodeEnum.MLME_SYNC => "MLME_SYNC", 
			CommandOpcodeEnum.MLME_SYNC_LOSS => "MLME_SYNC_LOSS", 
			CommandOpcodeEnum.MLME_POLL => "MLME_POLL", 
			CommandOpcodeEnum.VS_DUT_ENABLE => "VS_DUT_ENABLE", 
			CommandOpcodeEnum.VS_DUT_TX_TEST => "VS_DUT_TX_TEST", 
			CommandOpcodeEnum.VS_DUT_RX_TEST => "VS_DUT_RX_TEST", 
			CommandOpcodeEnum.VS_DUT_RX_STAT => "VS_DUT_RX_STAT", 
			CommandOpcodeEnum.VS_DUT_RX_RSSI => "VS_DUT_RX_RSSI", 
			CommandOpcodeEnum.VS_DUT_END_TEST => "VS_DUT_END_TEST", 
			CommandOpcodeEnum.VS_PEEK => "VS_PEEK", 
			CommandOpcodeEnum.VS_POKE => "VS_POKE", 
			CommandOpcodeEnum.VS_NVM_GET => "VS_NVM_GET", 
			CommandOpcodeEnum.VS_NVM_SET => "VS_NVM_SET", 
			CommandOpcodeEnum.VS_WHITELIST => "VS_WHITELIST", 
			CommandOpcodeEnum.VS_DUT_TX_RAW => "VS_DUT_TX_RAW", 
			CommandOpcodeEnum.VS_DUT_CCA_SCAN => "VS_DUT_CCA_SCAN", 
			CommandOpcodeEnum.COMMAND_ERROR => "COMMAND_ERROR", 
			_ => "Invalid CommandOpcode Value", 
		};
	}

	public static string CommandOpcodeToDescription()
	{
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.AppendLine("0x1 = MCPS_DATA_REQUEST");
		stringBuilder.AppendLine("0x2 = MCPS_DATA_PURGE");
		stringBuilder.AppendLine("0x20 = MLME_ASSOCIATE");
		stringBuilder.AppendLine("0x21 = MLME_DISASSOCIATE");
		stringBuilder.AppendLine("0x22 = MLME_BEACON_NOTIFY");
		stringBuilder.AppendLine("0x23 = MLME_GET");
		stringBuilder.AppendLine("0x24 = MLME_GTS");
		stringBuilder.AppendLine("0x25 = MLME_ORPHAN");
		stringBuilder.AppendLine("0x26 = MLME_RESET");
		stringBuilder.AppendLine("0x27 = MLME_RX_ENABLE");
		stringBuilder.AppendLine("0x28 = MLME_SCAN");
		stringBuilder.AppendLine("0x29 = MLME_COMM_STATUS");
		stringBuilder.AppendLine("0x2A = MLME_SET");
		stringBuilder.AppendLine("0x2B = MLME_START");
		stringBuilder.AppendLine("0x2C = MLME_SYNC");
		stringBuilder.AppendLine("0x2D = MLME_SYNC_LOSS");
		stringBuilder.AppendLine("0x2E = MLME_POLL");
		stringBuilder.AppendLine("0x80 = VS_DUT_ENABLE");
		stringBuilder.AppendLine("0x81 = VS_DUT_TX_TEST");
		stringBuilder.AppendLine("0x82 = VS_DUT_RX_TEST");
		stringBuilder.AppendLine("0x83 = VS_DUT_RX_STAT");
		stringBuilder.AppendLine("0x84 = VS_DUT_RX_RSSI");
		stringBuilder.AppendLine("0x85 = VS_DUT_END_TEST");
		stringBuilder.AppendLine("0x86 = VS_PEEK");
		stringBuilder.AppendLine("0x87 = VS_POKE");
		stringBuilder.AppendLine("0x88 = VS_NVM_GET");
		stringBuilder.AppendLine("0x89 = VS_NVM_SET");
		stringBuilder.AppendLine("0x8A = VS_WHITELIST");
		stringBuilder.AppendLine("0x8B = VS_DUT_TX_RAW");
		stringBuilder.AppendLine("0x8C = VS_DUT_CCA_SCAN");
		stringBuilder.AppendLine("0xFF = COMMAND_ERROR");
		return stringBuilder.ToString();
	}
}
