#include "RenderLayerMembershipCommand.h"

namespace UsdLayerManager {

// ─── RenderLayerAddMembersCommand ─────────────────────────────────────────

RenderLayerAddMembersCommand::RenderLayerAddMembersCommand(RenderLayerManager* mgr,
                                                           std::string layerId,
                                                           std::vector<pxr::SdfPath> paths)
    : m_mgr(mgr)
    , m_layerId(std::move(layerId))
    , m_paths(std::move(paths))
    , m_description(m_paths.size() == 1
          ? ("Add " + m_paths.front().GetString() + " to Render Layer")
          : ("Add " + std::to_string(m_paths.size()) + " Members to Render Layer"))
{
}

void RenderLayerAddMembersCommand::Execute() {
    if (!m_mgr) return;
    for (const auto& p : m_paths)
        m_mgr->AddMember(m_layerId, p);
}

void RenderLayerAddMembersCommand::Undo() {
    if (!m_mgr) return;
    for (const auto& p : m_paths)
        m_mgr->RemoveMember(m_layerId, p);
}

// ─── RenderLayerRemoveMembersCommand ──────────────────────────────────────

RenderLayerRemoveMembersCommand::RenderLayerRemoveMembersCommand(RenderLayerManager* mgr,
                                                                 std::string layerId,
                                                                 std::vector<pxr::SdfPath> paths)
    : m_mgr(mgr)
    , m_layerId(std::move(layerId))
    , m_paths(std::move(paths))
    , m_description(m_paths.size() == 1
          ? ("Remove " + m_paths.front().GetString() + " from Render Layer")
          : ("Remove " + std::to_string(m_paths.size()) + " Members from Render Layer"))
{
}

void RenderLayerRemoveMembersCommand::Execute() {
    if (!m_mgr) return;
    for (const auto& p : m_paths)
        m_mgr->RemoveMember(m_layerId, p);
}

void RenderLayerRemoveMembersCommand::Undo() {
    if (!m_mgr) return;
    for (const auto& p : m_paths)
        m_mgr->AddMember(m_layerId, p);
}

} // namespace UsdLayerManager
