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

#pragma once

#include "commands.hpp"

namespace nostalgia::gfx {

class DrawCommand: public TileSheetCommand {
	private:
		struct Change {
			uint32_t idx = 0;
			uint16_t oldPalIdx = 0;
			constexpr Change(uint32_t pIdx, uint16_t pOldPalIdx) noexcept {
				idx = pIdx;
				oldPalIdx = pOldPalIdx;
			}
		};
		TileSheet &m_img;
		TileSheet::SubSheetIdx m_subSheetIdx;
		ox::Vector<Change, 8> m_changes;
		int m_palIdx = 0;

	public:
		DrawCommand(
				TileSheet &img,
				TileSheet::SubSheetIdx subSheetIdx,
				std::size_t idx,
				int palIdx) noexcept;

		DrawCommand(
				TileSheet &img,
				TileSheet::SubSheetIdx subSheetIdx,
				ox::SpanView<std::size_t> const &idxList,
				int palIdx) noexcept;

		bool append(std::size_t idx) noexcept;

		bool append(ox::SpanView<std::size_t> const &idxList) noexcept;

		void lineUpdate(ox::Point a, ox::Point b) noexcept;

		ox::Error redo() noexcept final;

		ox::Error undo() noexcept final;

		[[nodiscard]]
		int commandId() const noexcept final;

		[[nodiscard]]
		TileSheet::SubSheetIdx const &subsheetIdx() const noexcept override;

		void finish() noexcept;

};

}
