#pragma once
#include <string>
#include <vector>
#include "geometry/Vec2.h"

namespace MC {

// ── Scenery category ──────────────────────────────────────────────────────────
enum class SceneryCategory {
    Platform,
    Building,
    Station,
    Signal,
    Bridge,
    Tunnel,
    Road,
    Tree,
    Vehicle,
    Special,
    Misc,
};

// ── A shape primitive used for rendering a scenery item ───────────────────────
// All coordinates are in mm, relative to the item's local origin (top-left).
// Y increases downward (canvas convention).
enum class SceneryShapeType {
    FilledRect,     // axis-aligned filled rectangle
    FilledEllipse,  // axis-aligned filled ellipse
    FilledPolygon,  // arbitrary filled polygon
    OutlineRect,    // outline only rectangle (windows, doors etc.)
    OutlineEllipse,
    Line,           // thin line (road marking, rail etc.)
    Text,           // text label
};

struct SceneryColor {
    uint8_t r, g, b, a = 255;
};

struct SceneryShape {
    SceneryShapeType type;
    SceneryColor     fill;
    SceneryColor     stroke    = {0,0,0,255};
    int              strokePx  = 1;       // stroke width in screen pixels

    // For rect/ellipse: (x,y) = top-left, (w,h) = size
    // For polygon: pts used, x/y/w/h ignored
    // For line: x,y = start; w,h = end (offsets from origin)
    // For text: (x,y) = center, h = font size in mm; text in textStr field
    double x = 0, y = 0, w = 0, h = 0;
    std::vector<Vec2> pts;  // for FilledPolygon
    std::string textStr;    // for Text
};

// ── Catalog entry for one scenery item ───────────────────────────────────────
struct SceneryItem {
    std::string      id;           // unique key e.g. "platform"
    std::string      displayName;  // shown in palette
    SceneryCategory  category;
    double           widthMm;      // bounding box width
    double           heightMm;     // bounding box height
    bool             rotatable = true;
    // When true, item is shown only when the user has Z-Track selected.
    // Default false = available on HO systems (C/K/TRIX) and hidden on Z.
    bool             zScale    = false;

    std::vector<SceneryShape> shapes;  // draw in order, back to front

    std::string categoryName() const {
        switch (category) {
            case SceneryCategory::Platform: return "Platforms";
            case SceneryCategory::Building: return "Buildings";
            case SceneryCategory::Station:  return "Stations";
            case SceneryCategory::Signal:   return "Signals";
            case SceneryCategory::Bridge:   return "Bridges";
            case SceneryCategory::Tunnel:   return "Tunnels";
            case SceneryCategory::Road:     return "Roads";
            case SceneryCategory::Tree:     return "Nature";
            case SceneryCategory::Vehicle:  return "Vehicles";
            case SceneryCategory::Special:  return "Special";
            case SceneryCategory::Misc:     return "Other";
        }
        return "Other";
    }
};

} // namespace MC
