/*
 * Copyright (c) 2018 Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
 */

#include "fw_info_app.h"

#include <zephyr/kernel.h>
#include <stdio.h>
#include <zephyr/logging/log_ctrl.h>
#include "device_location.h"
#include "ncs_version.h"

#include "macros_common.h"

#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(fw_info, CONFIG_FW_INFO_LOG_LEVEL);

static const char COMPILE_DATE[] = "Wed Oct 22 14:43:54 2025";
/* NOTE: The string below is used by the Nordic CI system */
static const char NRF5340_CORE[] = "nRF5340 Audio nRF5340 Audio DK cpuapp";

int fw_info_app_print(void)
{
	/* NOTE: The string below is used by the Nordic CI system */
	LOG_INF(COLOR_GREEN "\r\n\t %s \
			    \r\n\t NCS base version: %s \
			    \r\n\t Cmake run : %s" COLOR_RESET,
		NRF5340_CORE, NCS_VERSION_STRING, COMPILE_DATE);

#if (CONFIG_DEBUG)
	int ret;

	LOG_INF("------- DEBUG BUILD -------");

#if (CONFIG_AUDIO_DEV == HEADSET)
	enum bt_audio_location location;

	device_location_get(&location);

	if (location == BT_AUDIO_LOCATION_MONO_AUDIO){
		LOG_ERR("HEADSET location %s is not supported", bt_audio_location_bit_to_str(location));
		return -EINVAL;
	}

	for (int i = 0; i < (CHAR_BIT * sizeof(enum bt_audio_location)); i++) {
		if (location & BIT(i)) {
			LOG_INF(COLOR_CYAN "HEADSET location: %s" COLOR_RESET, bt_audio_location_bit_to_str(BIT(i)));
		}
	}

	if (location == BT_AUDIO_LOCATION_FRONT_LEFT) {
		ret = log_set_tag(HS_LOC_L_TAG);
	} else if (location == BT_AUDIO_LOCATION_FRONT_RIGHT) {
		ret = log_set_tag(HS_LOC_R_TAG);
	} else if (location == (BT_AUDIO_LOCATION_FRONT_LEFT | BT_AUDIO_LOCATION_FRONT_RIGHT)) {
		ret = log_set_tag(HS_LOC_LR_TAG);
	} else {
		ret = log_set_tag(HS_LOC_OTHER_TAG);
	}

	if (ret) {
		return ret;
	}

#elif CONFIG_AUDIO_DEV == GATEWAY
	ret = log_set_tag(GW_TAG);
	if (ret) {
		return ret;
	}
	LOG_INF(COLOR_CYAN "GATEWAY device" COLOR_RESET);
#endif /* (CONFIG_AUDIO_DEV == HEADSET) */
#endif /* (CONFIG_DEBUG) */

	return 0;
}
