//
// Created by Dan Crosby on 5/28/20.
//

#ifndef EAGLE0_STARTFIRECOMMAND_HPP
#define EAGLE0_STARTFIRECOMMAND_HPP

#include <utility>

#include "src/main/cpp/net/eagle0/shardok/library/ShardokCommand.hpp"
#include "src/main/cpp/net/eagle0/shardok/library/map/Coordinates.hpp"
#include "src/main/cpp/net/eagle0/shardok/library/settings/GameSettings.hpp"

namespace shardok {

using Terrain = net::eagle0::shardok::storage::fb::Terrain;

class StartFireCommand : public ShardokCommand {
private:
    [[nodiscard]] auto ExecuteWithRoll(const GameStateW& currentState, double roll) const
            -> vector<ActionResult>;

protected:
    [[nodiscard]] auto InternalExecute(
            const GameStateW& currentState,
            const std::shared_ptr<RandomGenerator>& generator) const
            -> vector<ActionResult> override;

    const SettingsGetter settings;
    const UnitId actorId;
    const Coords target;
    const Terrain targetTerrain;
    const PercentileRollOdds odds;

public:
    StartFireCommand(
            const SettingsGetter& getter,
            PlayerId playerId,
            UnitId actorId,
            Coords target,
            Terrain targetTerrain,
            PercentileRollOdds odds);

    ~StartFireCommand() override = default;

    auto GetCommandType() const -> CommandType override {
        return net::eagle0::shardok::common::START_FIRE_COMMAND;
    }

    auto GetCommandProto() const -> CommandProto override;

    [[nodiscard]] auto CanBeFollowUp() const -> bool override { return true; }
    [[nodiscard]] auto CanDoWithLowMorale() const -> bool override { return false; }
    [[nodiscard]] auto CanDoWhileStunned() const -> bool override { return false; }
    [[nodiscard]] auto CanDoWithLowVigor() const -> bool override { return false; }
    [[nodiscard]] auto CanDoAfterMovingIntoZoc() const -> bool override { return false; }
    [[nodiscard]] auto IsRequiredToEndTurn() const -> bool override { return false; }
    [[nodiscard]] auto HasOdds() const -> bool override { return true; }
    [[nodiscard]] auto GetOddsPercentile() const -> int32_t override;

    [[nodiscard]] int GetActorUnitId() const override { return actorId; }
    [[nodiscard]] MapIndex GetTargetRow() const override { return target.row(); }
    [[nodiscard]] MapIndex GetTargetColumn() const override { return target.column(); }
};
}  // namespace shardok

#endif  // EAGLE0_STARTFIRECOMMAND_HPP
