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

#include "commands.hpp"
#include "addcolorcommand.hpp"

namespace nostalgia::gfx {

AddColorCommand::AddColorCommand(Palette &pal, Color16 const color, size_t const idx) noexcept:
	m_pal(pal),
	m_color(color),
	m_idx(idx) {}

int AddColorCommand::commandId() const noexcept {
	return static_cast<int>(PaletteEditorCommandId::AddColor);
}

ox::Error AddColorCommand::redo() noexcept {
	m_pal.colorNames.emplace(m_idx, ox::sfmt("Color {}", m_pal.colorNames.size() + 1));
	for (auto &page : m_pal.pages) {
		page.colors.emplace(m_idx, m_color);
	}
	return {};
}

ox::Error AddColorCommand::undo() noexcept {
	OX_RETURN_ERROR(m_pal.colorNames.erase(m_idx));
	for (auto &page : m_pal.pages) {
		OX_RETURN_ERROR(page.colors.erase(m_idx));
	}
	return {};
}

}
