#ifndef JNR_PARALLAX_H
#define JNR_PARALLAX_H

#include <SDL2/SDL.h>
#include <stdbool.h>
#include "config.h"

/* Forward declarations */
typedef struct Camera Camera;

/* A single parallax layer */
typedef struct ParallaxLayer {
    SDL_Texture *texture;       /* the background image               */
    int          tex_w, tex_h;  /* texture dimensions in pixels       */
    float        scroll_x;      /* horizontal scroll factor (0=fixed, 1=full) */
    float        scroll_y;      /* vertical scroll factor             */
    bool         active;        /* whether this layer is in use       */
    bool         owns_texture;  /* true if we generated it (must free) */
} ParallaxLayer;

/* A non-tiling sprite drawn once in the background (e.g. Earth from moon) */
typedef struct ParallaxFeature {
    SDL_Texture *texture;       /* sprite image                       */
    int          tex_w, tex_h;  /* sprite dimensions                  */
    float        x, y;          /* base position (pixels, screen)     */
    float        scroll_x;      /* horizontal scroll factor           */
    float        scroll_y;      /* vertical scroll factor             */
    bool         active;
} ParallaxFeature;

/* Parallax background system — two tiling layers + optional feature sprite */
typedef struct Parallax {
    ParallaxLayer   far_layer;  /* distant background (stars)         */
    ParallaxLayer   near_layer; /* mid-ground background (nebula)     */
    ParallaxFeature feature;    /* non-tiling overlay (planet, etc.)  */
} Parallax;

/* Initialize parallax (zeroes everything) */
void parallax_init(Parallax *p);

/* Set a layer from an existing texture (loaded via assets) */
void parallax_set_far(Parallax *p, SDL_Texture *tex, float scroll_x, float scroll_y);
void parallax_set_near(Parallax *p, SDL_Texture *tex, float scroll_x, float scroll_y);

/* Generate procedural starfield texture (far layer) */
void parallax_generate_stars(Parallax *p, SDL_Renderer *renderer);

/* Generate procedural nebula/dust texture (near layer) */
void parallax_generate_nebula(Parallax *p, SDL_Renderer *renderer);

/* Themed parallax generation styles */
typedef enum ParallaxStyle {
    PARALLAX_STYLE_DEFAULT,     /* generic space (same as stars+nebula)     */
    PARALLAX_STYLE_ALIEN_SKY,   /* alien planet surface: dusty, hazy       */
    PARALLAX_STYLE_INTERIOR,    /* indoor base: panels, pipes, structural  */
    PARALLAX_STYLE_DEEP_SPACE,  /* space station windows: vivid stars      */
    PARALLAX_STYLE_MOON,        /* moon surface: craters, grey terrain     */
    PARALLAX_STYLE_MARS,        /* Mars: salmon sky, red mesas, dust      */
} ParallaxStyle;

/* Generate both layers with a unified style */
void parallax_generate_themed(Parallax *p, SDL_Renderer *renderer, ParallaxStyle style);

/* Render both layers (call before tile/entity rendering) */
void parallax_render(const Parallax *p, const Camera *cam, SDL_Renderer *renderer);

/* Free generated textures (not file-loaded ones — asset manager owns those) */
void parallax_free(Parallax *p);

#endif /* JNR_PARALLAX_H */
