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

#include "drivers/fs/fs.h"
#include "boot/typedef.h"
#include "boot/answer_code.h"
#include "boot/entry.h"

int mount() {
    printf("fs: mount");
    return 0;
}
int unmount() {
    printf("fs: unmount");
    return 0;
}
int format() {
    printf("fs: format");
    return 0;
}
int get_info() {
    printf("fs: get_info");
    return 0;
}
int is_present() {
    printf("fs: is_present");
    return 0;
}
int get_vfs_config() {
    printf("fs: get_vfs_config");
    return 0;
}

int init_fs(apios_main_table_t *apios_table) {

    (void)apios_table;

    if (apios_table == NULL) {
        if (load_log) printf("The driver table is not initialized\n");
        return APIOS_ERR_NOT_INITIALIZED;
    }

    static driver_fn_t fs_function[] = {
        {
            .name = "mount",
            .driver_fn = mount,
        },
        {
            .name = "unmount",
            .driver_fn = unmount,
        },
        {
            .name = "format",
            .driver_fn = format,
        },
        {
            .name = "get_info",
            .driver_fn = get_info,
        },
        {
            .name = "is_present",
            .driver_fn = is_present,
        },
        {
            .name = "get_vfs_config",
            .driver_fn = get_vfs_config,
        }
    };

    driver_api_t *fs_api = (driver_api_t *)malloc(sizeof(driver_api_t));
    fs_api->driver_version = 1;
    fs_api->fn_count = (int)(sizeof(fs_function)/sizeof(fs_function[0]));
    fs_api->functions = fs_function;

    driver_header_t *driver_header = (driver_header_t *)malloc(sizeof(driver_header_t));
    strcpy(driver_header->driver_name, "FileSystem");
    driver_header->api = fs_api;

    apios_table->drivers[apios_table->drivers_count] = driver_header;
    apios_table->drivers_count++;


    return OS_OK;
}