//
//  HolyWaveCommandFactory.cpp
//  eagle0_engine
//
//  Created by Dan Crosby on 1/9/19.
//  Copyright © 2019 none. All rights reserved.
//

#include "HolyWaveCommandFactory.hpp"

#include "src/main/cpp/net/eagle0/common/ContainerUtils.hpp"
#include "src/main/cpp/net/eagle0/shardok/library/commands/HolyWaveCommand.hpp"
#include "src/main/cpp/net/eagle0/shardok/library/util/HexMapUtils.hpp"

namespace shardok {

[[nodiscard]] auto CanHolyWave(const SettingsGetter &settings, const Unit *unit) -> bool;

HolyWaveCommandFactory::HolyWaveCommandFactory(const SettingsGetter &getter) : settings(getter) {}

auto HolyWaveCommandFactory::MakeHolyWaveAction(PlayerId playerId, UnitId actorId) const
        -> CommandSPtr {
    return std::make_shared<HolyWaveCommand>(
            settings.ActionCostFor(settings.Backing().holy_wave_action_point_cost()),
            playerId,
            actorId,
            settings);
}

void HolyWaveCommandFactory::AddAvailableHolyWaveCommands(
        CommandList &commands,
        const Unit *unit,
        const ActionPoints remainingActionPoints) const {
    if (!unit->has_attached_hero()) return;
    if (!settings.ActionCostFor(settings.Backing().holy_wave_action_point_cost())
                 .IsPossible(remainingActionPoints))
        return;

    if (CanHolyWave(settings, unit)) {
        commands.push_back(MakeHolyWaveAction(unit->player_id(), unit->unit_id()));
    }
}
void HolyWaveCommandFactory::AddAvailableCommands(
        CommandList &commands,
        const CommandFactory::CommandParams &params) const {
    AddAvailableHolyWaveCommands(commands, params.unit, params.remainingActionPoints);
}

auto CanHolyWave(const SettingsGetter &settings, const Unit *unit) -> bool {
    if (!unit->has_attached_hero()) return false;

    return unit->attached_hero().profession_info().profession() ==
           net::eagle0::shardok::storage::fb::Profession_PALADIN;
}

}  // namespace shardok
