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

#ifndef EAGLE0_FEARCOMMAND_HPP
#define EAGLE0_FEARCOMMAND_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 Unit = net::eagle0::shardok::storage::fb::Unit;

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

    const ActionCost cost;
    const UnitId actorId;
    const Coords target;
    const UnitId victimId;
    const PercentileRollOdds believedOdds;
    const int16_t fearBaseOdds;
    const double fearDebuf;
    const double fearFailedBuf;
    int charismaXp;
    int minimumKnowledge;

public:
    FearCommand(
            const ActionCost& cost,
            const PlayerId playerId,
            const UnitId actorId,
            const Coords target,
            const UnitId victimId,
            PercentileRollOdds believedOdds,
            const int16_t fearBaseOdds,
            const double fearDebuf,
            const double fearFailedBuf,
            const int charismaXp,
            const int minimumKnowledge)
        : ShardokCommand(playerId),
          cost(cost),
          actorId(actorId),
          target(target),
          victimId(victimId),
          believedOdds(std::move(believedOdds)),
          fearBaseOdds(fearBaseOdds),
          fearDebuf(fearDebuf),
          fearFailedBuf(fearFailedBuf),
          charismaXp(charismaXp),
          minimumKnowledge(minimumKnowledge){};

    ~FearCommand() override = default;

    [[nodiscard]] auto ExecuteWithRoll(const GameStateW& currentState, double roll) const
            -> vector<ActionResult>;

    [[nodiscard]] auto GetCommandType() const -> CommandType override {
        return net::eagle0::shardok::common::FEAR_COMMAND;
    }

    [[nodiscard]] auto GetCommandProto() const -> CommandProto override;

    [[nodiscard]] static auto GetFearOdds(
            int16_t fearBaseOdds,
            double attackerCharisma,
            double attackerWisdom,
            double defenderCharisma) -> PercentileRollOdds;

    [[nodiscard]] auto HasOdds() const -> bool override { return true; }
    [[nodiscard]] auto GetOddsPercentile() const -> int32_t override;
};
}  // namespace shardok

#endif  // EAGLE0_FEARCOMMAND_HPP
