#ifndef LASERTAG_UTILS_H
#define LASERTAG_UTILS_H

#include <stdint.h>

// ANSI Escape Codes für die Formatierung
#define ANSI_BOLD  "\x1b[1m"
#define ANSI_RESET "\x1b[0m"

// Das BOLD-Makro
#define BOLD(s) ANSI_BOLD s ANSI_RESET

/**
 * @file lasertag_utils.h
 * @brief Common utility functions for the lasertag system.
 */

/**
 * @brief Initialize the common lasertag utilities (NVS, Shell, etc.).
 */
void lasertag_utils_init(void);

/**
 * @brief Get the current device name.
 * @return Pointer to the device name string.
 */
const char* lasertag_get_device_name(void);

/**
 * @brief Set the device name.
 * @param name Pointer to the name string.
 * @param len Length of the name.
 * @return 0 on success, negative error code otherwise.
 */
int lasertag_set_device_name(const char *name, size_t len);

/**
 * @brief Initialize the watchdog timer for lasertag utilities.
 * @return 0 on success, negative error code otherwise.
 */
int lasertag_init_watchdog(void);

/**
 * @brief Feed the watchdog timer to prevent a system reset.
 */
void lasertag_feed_watchdog(void);
#endif /* LASERTAG_UTILS_H */

/**
 * @brief Calculate CRC8 checksum for the given data.
 * @param data Pointer to the data buffer.
 * @param len Length of the data buffer.
 * @return Calculated CRC8 checksum.
 */
uint8_t lastertag_crc8 (const uint8_t *data, size_t len);

/**
 * ANSI Defines for bold text formatting in logs.
 */
#define ANSI_RESET "\x1b[0m"

#define ANSI_BOLD  "\x1b[1m"

#define ANSI_BRIGHT "\x1b[97m"
#define ANSI_GREEN "\x1b[32m"
#define ANSI_YELLOW "\x1b[33m"
#define ANSI_RED "\x1b[31m"
#define ANSI_BLUE "\x1b[34m"

#define FORMAT_BOLD(s) ANSI_BOLD s ANSI_RESET

#define FORMAT_BRIGHT(s) ANSI_BRIGHT s ANSI_RESET
#define FORMAT_BRIGHT_BOLD(s) ANSI_BRIGHT ANSI_BOLD s ANSI_RESET

#define FORMAT_GREEN(s) ANSI_GREEN s ANSI_RESET
#define FORMAT_GREEN_BOLD(s) ANSI_GREEN ANSI_BOLD s ANSI_RESET
#define FORMAT_YELLOW(s) ANSI_YELLOW s ANSI_RESET
#define FORMAT_YELLOW_BOLD(s) ANSI_YELLOW ANSI_BOLD s ANSI_RESET
#define FORMAT_RED(s) ANSI_RED s ANSI_RESET
#define FORMAT_RED_BOLD(s) ANSI_RED ANSI_BOLD s ANSI_RESET
#define FORMAT_BLUE(s) ANSI_BLUE s ANSI_RESET
#define FORMAT_BLUE_BOLD(s) ANSI_BLUE ANSI_BOLD s ANSI_RESET


