#pragma once #include #include #include "../CommandBus/CommandEnvelope.hpp" #include "../CommandBus/CommandResult.hpp" // --------------------------------------------------------------------------- // ICommandHandler // // Interface every domain handler implements. // // - commands() declares which command names this handler owns. // The CommandBus iterates this list at registration time and builds // its lookup map automatically — no manual registration per command. // // - execute() receives a fully-parsed CommandEnvelope and returns a // CommandResult. It must never call envelope.reply() directly — // the bus handles that after execute() returns. // // Example: // class PlaybackHandler : public ICommandHandler { // public: // explicit PlaybackHandler(Player& player); // std::vector commands() const override { return { "playback" }; } // CommandResult execute(const CommandEnvelope& envelope) override; // private: // Player& _player; // }; // --------------------------------------------------------------------------- class ICommandHandler { public: virtual ~ICommandHandler() = default; // Returns every command name this handler is responsible for. // The bus registers all of them to the same handler instance. virtual std::vector commands() const = 0; // Execute the command described by envelope and return the result. // Must not throw. Must not call envelope.reply() — the bus owns that. virtual CommandResult execute(const CommandEnvelope& envelope) = 0; };