// main.cpp - Punt d'entrada amb SDL_MAIN_USE_CALLBACKS
// © 2026 JailDesigner
//
// El Director és EL programa: posseeix la configuració, els subsistemes i
// l'estat. Aquestes 4 callbacks són la fontaneria mínima que SDL3 demana
// per arrencar, processar events, iterar i tancar.

#define SDL_MAIN_USE_CALLBACKS 1

#include <SDL3/SDL.h>
#include <SDL3/SDL_main.h>

#include <memory>

#include "core/system/director.hpp"

auto SDL_AppInit(void** appstate, int argc, char* argv[]) -> SDL_AppResult {
    auto director = std::make_unique<Director>(argc, argv);
    *appstate = director.release();
    return SDL_APP_CONTINUE;
}

auto SDL_AppEvent(void* appstate, SDL_Event* event) -> SDL_AppResult {
    auto* director = static_cast<Director*>(appstate);
    return director->handleEvent(*event);
}

auto SDL_AppIterate(void* appstate) -> SDL_AppResult {
    auto* director = static_cast<Director*>(appstate);
    return director->iterate();
}

void SDL_AppQuit(void* appstate, SDL_AppResult /*result*/) {
    // Reabsorbim la propietat: el destructor del Director allibera tot.
    std::unique_ptr<Director> director(static_cast<Director*>(appstate));
}
