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

#include "movesubsheetcommand.hpp"

namespace nostalgia::gfx {

MoveSubSheetCommand::MoveSubSheetCommand(
	TileSheet &img,
	TileSheet::SubSheetIdx src,
	TileSheet::SubSheetIdx dst) noexcept:
		m_img{img},
		m_src{std::move(src)},
		m_dst{std::move(dst)} {
}

ox::Error MoveSubSheetCommand::redo() noexcept {
	m_active = &m_dst;
	TileSheet::SubSheet ss = std::move(getSubSheet(m_img, m_src));
	OX_RETURN_ERROR(rmSubSheet(m_img, m_src));
	return insertSubSheet(m_img, m_dst, std::move(ss));
}

ox::Error MoveSubSheetCommand::undo() noexcept {
	m_active = &m_src;
	TileSheet::SubSheet ss = std::move(getSubSheet(m_img, m_dst));
	OX_RETURN_ERROR(rmSubSheet(m_img, m_dst));
	return insertSubSheet(m_img, m_src, std::move(ss));
}

int MoveSubSheetCommand::commandId() const noexcept {
	return static_cast<int>(CommandId::MoveSubSheet);
}

TileSheet::SubSheetIdx const &MoveSubSheetCommand::subsheetIdx() const noexcept {
	return *m_active;
}

}
