#pragma once

#include <flecs.h>
#include <memory>

namespace Ogre {
    class SceneManager;
}

class ProceduralMaterialSystem {
public:
    ProceduralMaterialSystem(flecs::world& world, Ogre::SceneManager* sceneMgr);
    ~ProceduralMaterialSystem();
    
    // Initialize the system
    void initialize();
    
    // Main update - creates dirty materials
    void update();
    
    // Force recreate a specific material
    void recreateMaterial(flecs::entity entity);
    
    // Get the material name for an entity
    std::string getMaterialName(flecs::entity entity);
    
    // Check if material exists
    bool materialExists(const std::string& name);
    
private:
    flecs::world& m_world;
    Ogre::SceneManager* m_sceneMgr;
    
    flecs::query<struct ProceduralMaterialComponent> m_query;
    
    bool m_initialized = false;

    // Create the Ogre material
    void createMaterial(flecs::entity entity, struct ProceduralMaterialComponent& component);
    
    // Destroy the Ogre material
    void destroyMaterial(struct ProceduralMaterialComponent& component);
};
