package com.laseroptek.raman.utils.ext

/**
 * Returns the string name of a constant from the CMD object that matches the given integer value.
 *
 * @param value The integer value of the command (e.g., 0x01, 0x03).
 * @return The string name of the constant (e.g., "VERSION", "LASER_STATUS"),
 *         or "UNKNOWN_CMD" if not found.
 */
fun getCmdString(value: Int): String {
    return when(value) {
        0x01 -> "(0x%02X) VERSION -------".format(value)
        0x03 -> "(0x%02X) LASER_STATUS --".format(value)
        0x05 -> "(0x%02X) PURGE_BUBBLE --".format(value)
        0x06 -> "(0x%02X) DCD_GAS -------".format(value)
        0x07 -> "(0x%02X) SPRAY_DCD -----".format(value)
        0x08 -> "(0x%02X) HAND_PIECE ----".format(value)
        0x09 -> "(0x%02X) GUIDE_BEAM ----".format(value)
        0x0A -> "(0x%02X) HP_SHOT_COUNT -".format(value)
        0x0B -> "(0x%02X) ENERGE_METER --".format(value)
        0x0C -> "(0x%02X) TEMPERATURE ---".format(value)
        0x0D -> "(0x%02X) OVEN ----------".format(value)
        0x0F -> "(0x%02X) Q_SWITCH ------".format(value)
        0x10 -> "(0x%02X) ERROR ---------".format(value)
        0x11 -> "(0x%02X) WARNING -------".format(value)
        0x14 -> "(0x%02X) ENERGY_DETECT -".format(value)
        0x20 -> "(0x%02X) UPDATE_FIRMWARE".format(value)
        else -> "(0x%02X) UNKNOWN_CMD ---".format(value)
    }
}

/*
import com.laseroptek.raman.utils.ext.getCmdString // Don't forget to import it

fun processCommand(commandCode: Int) { // e.g., commandCode is 0x01
    // Use the helper function to get the string name
    val commandName = getCmdString(commandCode) // This will return "VERSION"

    // Now you can use it for logging
    Timber.d("Received command: $commandName (Code: 0x${commandCode.toString(16)})")

    // You can also use it in a when statement for clarity if needed,
    // though using the constants is still best practice for control flow.
    when (commandCode) {
        CMD.VERSION -> {
            // ... handle version command
        }
        // ... other cases
    }
}

fun processCommand(commandCode: Int) { // e.g., commandCode is 0x01
    // Use the helper function to get the string name// ... inside a function in MainViewModel
    val commandName = getCmdString(commandCode) // This will return "VERSION"fun processCommand(commandCode: Int) { // e.g., commandCode is 0x01
    // Use the helper function to get the string name
    // Now you can use it for logging    val commandName = getCmdString(commandCode) // This will return "VERSION"
    Timber.d("Received command: $commandName (Code: 0x${commandCode.toString(16)})")
    // Now you can use it for logging
    // You can also use it in a when statement for clarity if needed,    Timber.d("Received command: $commandName (Code: 0x${commandCode.toString(16)})")
    // though using the constants is still best practice for control flow.
    when (commandCode) {    // You can also use it in a when statement for clarity if needed,
        CMD.VERSION -> {    // though using the constants is still best practice for control flow.
            // ... handle version command    when (commandCode) {
        }        CMD.VERSION -> {
        // ... other cases            // ... handle version command
    }        }
}        // ... other cases
    }
}
*/