#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>
#include <lasertag_utils.h>
#include <thread_mgmt.h>
#include <ble_mgmt.h>
#include <game_mgmt.h>

LOG_MODULE_REGISTER(leader_app, CONFIG_LOG_DEFAULT_LEVEL);

int main(void)
{
    /* Initialize shared project logic and NVS */
    lasertag_utils_init();

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

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

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

    /* Initialize game management module */
    err = game_mgmt_init();
    if (err) {
        LOG_ERR("Game Management initialization failed (err %d)", err);
        return err;
    } else {
        LOG_INF("Game Management initialized successfully.");
    }

    return 0;
}