#ifndef JNR_PARTICLE_H
#define JNR_PARTICLE_H

#include <SDL2/SDL.h>
#include <stdbool.h>
#include "util/vec2.h"

/* Forward declaration */
typedef struct Camera Camera;

#define MAX_PARTICLES 1024

/* A single particle — lightweight, no collision */
typedef struct Particle {
    Vec2      pos;
    Vec2      vel;
    SDL_Color color;
    float     life;          /* remaining lifetime (seconds)       */
    float     max_life;      /* initial lifetime (for alpha fade)  */
    float     size;          /* render size in pixels              */
    float     drag;          /* velocity damping per second (0-1)  */
    float     gravity_scale; /* 0 = no gravity, 1 = full gravity  */
    bool      active;
} Particle;

/* Burst configuration for particle_emit() */
typedef struct ParticleBurst {
    Vec2      origin;          /* world position to emit from      */
    int       count;           /* number of particles              */
    float     speed_min;       /* min initial speed                */
    float     speed_max;       /* max initial speed                */
    float     life_min;        /* min lifetime                     */
    float     life_max;        /* max lifetime                     */
    float     size_min;        /* min particle size                */
    float     size_max;        /* max particle size                */
    float     spread;          /* cone half-angle in radians       */
    float     direction;       /* base angle in radians (0=right)  */
    float     drag;            /* velocity damping                 */
    float     gravity_scale;   /* gravity multiplier               */
    SDL_Color color;           /* base color                       */
    bool      color_vary;      /* randomly vary color slightly     */
} ParticleBurst;

/* Initialize the particle system */
void particle_init(void);

/* Emit a burst of particles */
void particle_emit(const ParticleBurst *burst);

/* Update all active particles */
void particle_update(float dt);

/* Render all active particles */
void particle_render(const Camera *cam);

/* Remove all active particles */
void particle_clear(void);

/* ── Preset bursts for common effects ──────────────── */

/* Small puff of debris (enemy death, impact) */
void particle_emit_death_puff(Vec2 pos, SDL_Color color);

/* Landing dust when player hits ground */
void particle_emit_landing_dust(Vec2 pos);

/* Small spark burst (projectile hit wall) */
void particle_emit_spark(Vec2 pos, SDL_Color color);

/* Jetpack exhaust burst (dash start — big plume opposite to dash_dir) */
void particle_emit_jetpack_burst(Vec2 pos, Vec2 dash_dir);

/* Jetpack exhaust trail (call each frame while dashing) */
void particle_emit_jetpack_trail(Vec2 pos, Vec2 dash_dir);

/* Blue flame burst (mixed into jetpack burst when boost is active) */
void particle_emit_jetpack_boost_burst(Vec2 pos, Vec2 dash_dir);

/* Continuous blue flame trail during jetpack boost (call each frame while dashing + boosted) */
void particle_emit_jetpack_boost_trail(Vec2 pos, Vec2 dash_dir);

/* Ambient blue glow from jetpack while boost is active but not dashing
 * (call each frame; facing_left determines exhaust side) */
void particle_emit_jetpack_boost_idle(Vec2 pos, bool facing_left);

/* Muzzle flash (short bright burst in shoot direction) */
void particle_emit_muzzle_flash(Vec2 pos, Vec2 shoot_dir);

/* Wall slide dust (small puffs while scraping against a wall) */
void particle_emit_wall_slide_dust(Vec2 pos, int wall_dir);

#endif /* JNR_PARTICLE_H */
