#include "internal/mana_c_api.h"
#include "internal/rxi/log.h"
#include <stdlib.h>
#include <string.h>

struct Context
{
};

MANA_DEFINE_PLUGIN_INIT(init)
{
    log_set_level(LOG_INFO);
    struct Context *ctx = calloc(1, sizeof(*ctx));
    log_info("init: ctx=%p, argc=%d", ctx, plugin_argc);
    for (int i = 0; i < plugin_argc; ++i)
    {
        log_info("init: argv[%d]=%s", i, plugin_argv[i]);
    }
    return ctx;
}

MANA_DEFINE_PLUGIN_SHUTDOWN(shutdown)
{
    log_info("shutdown: ctx=%p", context);
    free(context);
}

MANA_DEFINE_PLUGIN_BEGIN_RUN(begin_run)
{
    (void)descriptor_json;
    log_info("begin_run: ctx=%p", context);
    /* pretty useless as the json needs to be parsed back into some c structure describing the input
     */
    mana_status_t result;
    result.code = mana_status_ok;
    strncpy(result.message, "ok", sizeof(result.message));
    return result;
}

MANA_DEFINE_PLUGIN_END_RUN(end_run)
{
    (void)descriptor_json;
    log_info("end: ctx=%p", context);
    mana_status_t result;
    result.code = mana_status_ok;
    strncpy(result.message, "ok", sizeof(result.message));
    return result;
}

MANA_DEFINE_PLUGIN_EVENT_DATA(process_event)
{
    log_trace("event: ctx=%p, eventIndex=%d, arrayCount=%zu, totalBytes=%zu", context, eventIndex,
              arrayCount, totalBytes);
}

MANA_DEFINE_PLUGIN_SYSTEM_EVENT(process_system_event)
{
    log_debug("system_event: ctx=%p, size=%zu", context, size);
}

MANA_C_SINK_PLUGIN()
{
    mana_sink_plugin_t plugin;
    plugin.init = init;
    plugin.shutdown = shutdown;
    plugin.begin_run = begin_run;
    plugin.end_run = end_run;
    plugin.process_event = process_event;
    plugin.process_system_event = process_system_event;
    return plugin;
}
