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

#include "flipcommand.hpp"

#include <utility>

namespace nostalgia::gfx {

FlipXCommand::FlipXCommand(
		TileSheet &img,
		TileSheet::SubSheetIdx subSheetIdx,
		ox::Point const &a,
		ox::Point const &b) noexcept:
	m_img{img},
	m_subSheetIdx{std::move(subSheetIdx)},
	m_ptA{a},
	m_ptB{b} {}

ox::Error FlipXCommand::redo() noexcept {
	auto &ss = getSubSheet(m_img, m_subSheetIdx);
	flipX(ss, m_ptA, m_ptB);
	return {};
}

ox::Error FlipXCommand::undo() noexcept {
	auto &ss = getSubSheet(m_img, m_subSheetIdx);
	flipX(ss, m_ptA, m_ptB);
	return {};
}

int FlipXCommand::commandId() const noexcept {
	return static_cast<int>(CommandId::FlipX);
}

TileSheet::SubSheetIdx const &FlipXCommand::subsheetIdx() const noexcept {
	return m_subSheetIdx;
}


FlipYCommand::FlipYCommand(
		TileSheet &img,
		TileSheet::SubSheetIdx subSheetIdx,
		ox::Point const &a,
		ox::Point const &b) noexcept:
	m_img{img},
	m_subSheetIdx{std::move(subSheetIdx)},
	m_ptA{a},
	m_ptB{b} {}

ox::Error FlipYCommand::redo() noexcept {
	auto &ss = getSubSheet(m_img, m_subSheetIdx);
	flipY(ss, m_ptA, m_ptB);
	return {};
}

ox::Error FlipYCommand::undo() noexcept {
	auto &ss = getSubSheet(m_img, m_subSheetIdx);
	flipY(ss, m_ptA, m_ptB);
	return {};
}

int FlipYCommand::commandId() const noexcept {
	return static_cast<int>(CommandId::FlipY);
}

TileSheet::SubSheetIdx const &FlipYCommand::subsheetIdx() const noexcept {
	return m_subSheetIdx;
}

}
