#pragma once

#include "../CommandHistory.h"
#include "../RenderLayerManager.h"
#include <string>

namespace UsdLayerManager {

/// Undo removes the created layer via RenderLayerManager::DeleteRenderLayer.
class RenderLayerCreateCommand : public ICommand {
public:
    RenderLayerCreateCommand(RenderLayerManager* mgr, std::string name);
    void Execute() override;
    void Undo()    override;
    std::string GetDescription() const override { return m_description; }

    /// Valid after Execute() — the new layer's identifier, so the panel can
    /// select it immediately.
    const std::string& GetCreatedLayerId() const { return m_layerId; }

private:
    RenderLayerManager* m_mgr;
    std::string          m_name;
    std::string          m_layerId;
    std::string          m_description;
};

/// The backing file is left on disk by RenderLayerManager::DeleteRenderLayer
/// (only the sublayer reference is removed), so Undo just re-inserts it.
class RenderLayerDeleteCommand : public ICommand {
public:
    RenderLayerDeleteCommand(RenderLayerManager* mgr, std::string layerId);
    void Execute() override;
    void Undo()    override;
    std::string GetDescription() const override { return m_description; }

private:
    RenderLayerManager* m_mgr;
    std::string          m_layerId;
    std::string          m_description;
};

class RenderLayerRenameCommand : public ICommand {
public:
    RenderLayerRenameCommand(RenderLayerManager* mgr, std::string layerId, std::string newName);
    void Execute() override;
    void Undo()    override;
    std::string GetDescription() const override { return m_description; }

private:
    RenderLayerManager* m_mgr;
    std::string          m_layerId;
    std::string          m_newName;
    std::string          m_oldName;
    std::string          m_description;
};

/// Switches the active render layer (or back to Default). RenderLayerManager
/// itself tracks the edit target to restore on returning to Default, so this
/// command only needs to remember which layer was active before the switch.
class RenderLayerActivateCommand : public ICommand {
public:
    /// targetLayerId empty = activate Default.
    RenderLayerActivateCommand(RenderLayerManager* mgr, std::string targetLayerId);
    void Execute() override;
    void Undo()    override;
    std::string GetDescription() const override { return m_description; }

private:
    RenderLayerManager* m_mgr;
    std::string          m_targetLayerId; // "" = Default
    std::string          m_priorLayerId;  // captured at construction; "" = Default
    std::string          m_description;
};

} // namespace UsdLayerManager
