#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>
#ifdef CONFIG_LASERTAG_UTILS
#include <lasertag_utils.h>
#endif
#ifdef CONFIG_THREAD_MGMT
#include <thread_mgmt.h>
#endif
#ifdef CONFIG_BLE_MGMT
#include <ble_mgmt.h>
#endif
#ifdef CONFIG_FS_MGMT
#include <fs_mgmt.h>
#endif

LOG_MODULE_REGISTER(vest_app, CONFIG_LOG_DEFAULT_LEVEL);

int main(void)
{
    int rc;

    #ifdef CONFIG_LASERTAG_UTILS
    /* Initialize shared project logic and NVS */
    lasertag_utils_init();
    #endif

    #ifdef CONFIG_FS_MGMT
    /* Initialize filesystem management */
    rc = fs_mgmt_init();
    if (rc) {
        LOG_ERR("Filesystem management initialization failed (err %d)", rc);
        return rc;
    }
    #endif

    #ifdef CONFIG_BLE_MGMT
    /* Initialize and start BLE management for provisioning */
    rc = ble_mgmt_init(LT_TYPE_VEST);
    if (rc) {
        LOG_ERR("BLE initialization failed (err %d)", rc);
        return rc;
    } else {
        LOG_INF("BLE Management initialized successfully.");
    }

    /* Start BLE advertising */
    rc = ble_mgmt_adv_start();
    if (rc) {
        LOG_ERR("BLE advertising start failed (err %d)", rc);
    } else {
        LOG_INF("BLE advertising started.");
    }
    #endif

    #ifdef CONFIG_THREAD_MGMT
    /* Initialize and start OpenThread stack */
    rc = thread_mgmt_init();
    if (rc) {
        LOG_ERR("Thread initialization failed (err %d)", rc);
    } else {
        LOG_INF("Vest Application successfully started with Thread Mesh.");
        return rc;
    }
    #endif

    while (1) {
        /* Main loop - handle high-level game logic here */
        k_sleep(K_MSEC(1000));
    }

    return 0;
}