#ifndef GENESIS_GEN_BLUEPRINTS_H
#define GENESIS_GEN_BLUEPRINTS_H

#include <stdint.h>
#include "grid.h"

/* Blueprint = a template for a machine (locked vault, reward room, monster
   den, etc.). Each blueprint has metadata (depth range, pocket size range,
   selection frequency) and a small list of features that describe what to
   place inside. Terrain and markers are intentionally generic so the Godot
   side can interpret them into game-specific content. */

typedef enum {
    BP_ROOM                = 1u << 0,  /* must occupy a room-sized region */
    BP_VESTIBULE           = 1u << 1,  /* attaches to a chokepoint pocket */
    BP_REWARD              = 1u << 2,  /* counts as a "reward" for pacing */
    BP_PURGE_INTERIOR      = 1u << 3,  /* clear liquid etc before building */
    BP_SURROUND_WITH_WALLS = 1u << 4,
    BP_OPEN_INTERIOR       = 1u << 5,  /* re-pave interior to floor */
    BP_IMPREGNABLE         = 1u << 6,  /* walls cannot be later modified */
    BP_ADOPT_KEY           = 1u << 7,  /* receives key from parent machine */
} blueprint_flags_t;

typedef enum {
    MF_EVERYWHERE          = 1u << 0,  /* feature occupies every interior cell */
    MF_BUILD_AT_ORIGIN     = 1u << 1,  /* placed at the blueprint's origin */
    MF_BUILD_VESTIBULE     = 1u << 2,  /* spawns a child vestibule (cascade) */
    MF_BUILD_IN_WALLS      = 1u << 3,
    MF_NEAR_ORIGIN         = 1u << 4,
    MF_FAR_FROM_ORIGIN     = 1u << 5,
    MF_PERMIT_BLOCKING     = 1u << 6,  /* may block a walking path */
    MF_TREAT_AS_BLOCKING   = 1u << 7,  /* others must route around */
    MF_IMPREGNABLE         = 1u << 8,
    MF_ALTERNATIVE         = 1u << 9,  /* pick one of a group */
    MF_GENERATE_KEY        = 1u << 10, /* this instance IS the key */
    MF_REQUIRE_ADOPTED_KEY = 1u << 11,
} feature_flags_t;

typedef struct {
    uint16_t terrain;    /* terrain_t to paint, 0 = unchanged */
    uint16_t marker;     /* marker_t to stamp into cell.surface, MK_NONE = none */
    uint8_t  min_count;  /* minimum instances required for acceptance */
    uint8_t  max_count;  /* upper bound on instances attempted */
    uint32_t flags;      /* feature_flags_t */
} feature_t;

#define MAX_FEATURES 8

typedef struct {
    const char *name;
    int16_t    depth_min;
    int16_t    depth_max;
    int16_t    room_size_min;   /* pocket size in cells */
    int16_t    room_size_max;
    uint16_t   frequency;       /* relative selection weight */
    uint32_t   flags;           /* blueprint_flags_t */
    uint8_t    feature_count;
    feature_t  features[MAX_FEATURES];
} blueprint_t;

/* The catalog. Defined in blueprints_data.c. NUM_BLUEPRINTS is the live
   length; index 0 is a no-op sentinel ("nothing") to match common usage. */
extern const blueprint_t blueprint_catalog[];
extern const int NUM_BLUEPRINTS;

#endif
