/**
 * @file hal_device_info.c
 * @brief HAL 设备信息实现（JieLi 平台）
 */

#include "hal_device_info.h"
#include "system/includes.h"
#include <stdio.h>
#include <string.h>

#define FIRMWARE_VERSION  "1.0.0"

int hal_device_get_device_id(char *buf, size_t size)
{
    if (!buf || size < 18) {
        return -1;
    }
    u8 mac[6];
    wifi_get_mac(mac);
    snprintf(buf, size, "%02X:%02X:%02X:%02X:%02X:%02X",
             mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
    return 0;
}

int hal_device_get_uuid(char *buf, size_t size)
{
    if (!buf || size < 33) {  /* 32 hex chars + '\0' */
        return -1;
    }
    /* 使用 NorFlash UUID 作为设备ID */
    u8 flash_uid[16];
    memset(flash_uid, 0, sizeof(flash_uid));
    memcpy(flash_uid, get_norflash_uuid(), 16);

    memset(buf, 0, size);
    for (int i = 0; i < 16; i++) {
        sprintf(&buf[i * 2], "%02X", flash_uid[i]);
    }
    return 0;
}

const char *hal_device_get_firmware_version(void)
{
    return FIRMWARE_VERSION;
}
