#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>

#include "FreeRTOS.h"
#include "boot/apios.h"
#include "drivers/fs/fs.h"
#include "drivers/monitor/driver.h"
#include "lib/video/vram.h"
#include "boot/answer_code.h"

#include "nvs_flash.h"
#include "nvs.h"

void log_result(int res, char *service_name){ 
    if (res == OS_OK) {
        printf("[  \033[0;32mOK\033[0m  ] APIOS initialization\n");
    } else {
        char *err_text = "Error";
        const char *msg = get_error(res);
        if (strncmp(msg, err_text, 5) == 0) {
            printf("[  \033[0;31mEROR\033[0m  ] %s initialization: %s (%d)\n", service_name, msg, res);
        } else {
            printf("[  \033[0;33mWARN\033[0m  ] %s initialization: %s (%d)\n", service_name, msg, res);
        }
    }
}

void OS_entry(void *pvParameters)
{
    printf("Initializing subsystems\n");

    log_result(init_apios(apios_table), "APIOS");
    
}