/**
 * @file error.c
 * @brief Implements the error subsystem: claims and names the libakgl status band.
 */

#include <akerror.h>

#include <akgl/error.h>

akerr_ErrorContext *akgl_error_init(void)
{
    PREPARE_ERROR(errctx);
    // Claim the whole band before naming anything in it: libakerror refuses a
    // name for a status we do not own. Any collision propagates to the caller
    // -- another component owning part of our range is an initialization
    // failure, not a warning.
    PASS(errctx, akerr_reserve_status_range(AKGL_ERR_BASE, AKGL_ERR_COUNT, AKGL_ERR_OWNER));
    PASS(errctx, akerr_register_status_name(AKGL_ERR_OWNER, AKGL_ERR_SDL, "SDL Error"));
    PASS(errctx, akerr_register_status_name(AKGL_ERR_OWNER, AKGL_ERR_REGISTRY, "Registry Error"));
    PASS(errctx, akerr_register_status_name(AKGL_ERR_OWNER, AKGL_ERR_HEAP, "Heap Error"));
    PASS(errctx, akerr_register_status_name(AKGL_ERR_OWNER, AKGL_ERR_BEHAVIOR, "Behavior Error"));
    PASS(errctx, akerr_register_status_name(AKGL_ERR_OWNER, AKGL_ERR_LOGICINTERRUPT, "Logic Interrupt"));
    PASS(errctx, akerr_register_status_name(AKGL_ERR_OWNER, AKGL_ERR_COLLISION, "Collision Error"));
    PASS(errctx, akerr_register_status_name(AKGL_ERR_OWNER, AKGL_ERR_UI, "UI Error"));
    SUCCEED_RETURN(errctx);
}
