#pragma once

#include <string>
#include <memory>
#include <flecs.h>
#include <Ogre.h>
#include <ProceduralTriangleBuffer.h>

/**
 * @brief Component that holds a procedural triangle buffer
 * 
 * The buffer contents are NOT serialized - only the configuration.
 * The buffer is rebuilt from Primitive children when needed.
 */
struct TriangleBufferComponent {
    // The actual triangle buffer (runtime only, not serialized)
    // Using shared_ptr because flecs needs to copy components
    std::shared_ptr<Procedural::TriangleBuffer> buffer;
    
    // Reference to entity with ProceduralTexture for UV mapping
    flecs::entity textureEntity;
    
    // Name of the rectangle in the texture atlas to use for UVs
    std::string textureRectName;
    
    // Reference to entity with ProceduralMaterial for material
    flecs::entity materialEntity;
    
    // Whether to attach to StaticGeometry instead of SceneNode
    bool useStaticGeometry = false;
    
    // Reference to StaticGeometry region entity (if useStaticGeometry is true)
    flecs::entity staticGeometryEntity;
    
    // Mesh name for the generated mesh
    std::string meshName;
    
    // Whether the buffer needs rebuilding
    bool dirty = true;
    
    // Whether the buffer has been converted to a mesh
    bool meshCreated = false;
    
    // Pointer to the created Ogre entity (if not using StaticGeometry)
    Ogre::Entity* ogreEntity = nullptr;
    
    void markDirty() { dirty = true; }
};
