/*
 * Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
 */

#include "commands.hpp"

#include "movepagecommand.hpp"

namespace nostalgia::gfx {

MovePageCommand::MovePageCommand(
		Palette &pal,
		size_t const srcIdx,
		size_t const dstIdx) noexcept:
	m_pal(pal),
	m_srcIdx(srcIdx),
	m_dstIdx(dstIdx) {}

int MovePageCommand::commandId() const noexcept {
	return static_cast<int>(PaletteEditorCommandId::MovePage);
}

ox::Error MovePageCommand::redo() noexcept {
	movePage(m_srcIdx, m_dstIdx);
	return {};
}

ox::Error MovePageCommand::undo() noexcept {
	movePage(m_dstIdx, m_srcIdx);
	return {};
}

void MovePageCommand::movePage(
		size_t const srcIdx, size_t const dstIdx) noexcept {
	auto page = std::move(m_pal.pages[srcIdx]);
	std::ignore = m_pal.pages.erase(srcIdx);
	m_pal.pages.emplace(dstIdx, std::move(page));
}

}
