#ifndef JNR_LEVEL_H
#define JNR_LEVEL_H

#include "engine/tilemap.h"
#include "engine/entity.h"
#include "engine/camera.h"
#include "engine/audio.h"
#include "engine/parallax.h"

typedef struct Level {
    Tilemap       map;
    EntityManager entities;
    Camera        camera;
    Parallax      parallax;
    Music         music;
    bool          music_started;

    /* ── Exit / transition state ─────────── */
    bool          exit_triggered;              /* player entered an exit zone  */
    char          exit_target[ASSET_PATH_MAX]; /* target level path            */

    /* ── Intro sequence state ────────────── */
    bool          has_intro_ship;              /* level has a spacecraft intro */
    bool          player_spawned;              /* player has been spawned      */

    /* ── Exit ship sequence state ────────── */
    bool          exit_ship_spawned;           /* exit spacecraft has been spawned */
    bool          exit_ship_boarded;           /* player has entered the ship     */
    int           exit_zone_idx;               /* which exit zone the ship is for */
} Level;

bool level_load(Level *level, const char *path);
bool level_load_generated(Level *level, Tilemap *gen_map);
void level_update(Level *level, float dt);
void level_render(Level *level, float interpolation);
void level_free(Level *level);

/* Returns true if the player has triggered a level exit.
 * The target path is stored in level->exit_target. */
bool level_exit_triggered(const Level *level);

#endif /* JNR_LEVEL_H */
