//
// Created by Dan Crosby on 6/3/20.
//

#ifndef EAGLE0_UPDATEGAMESTATUSACTION_HPP
#define EAGLE0_UPDATEGAMESTATUSACTION_HPP

#include <utility>

#include "src/main/cpp/net/eagle0/shardok/library/ShardokAction.hpp"
#include "src/main/cpp/net/eagle0/shardok/library/settings/GameSettings.hpp"
#include "src/main/cpp/net/eagle0/shardok/library/util/HexMapUtils.hpp"
#include "src/main/flatbuffer/net/eagle0/shardok/storage/game_state.hpp"

namespace shardok {
using GameState = net::eagle0::shardok::storage::fb::GameState;
using PlayerInfoFb = net::eagle0::shardok::storage::fb::PlayerInfo;

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

    const GameState* gameState;
    const CoordsSet criticalTileLocations;
    const SettingsGetter settingsGetter;
    const bool atEndOfRound;

    void ResolveHiddenLosers(ActionResult& actionResult) const;
    [[nodiscard]] auto SurvivingPlayers() const -> std::unordered_set<PlayerId>;
    [[nodiscard]] auto GetPlayerInfo(int playerId) const -> const PlayerInfoFb*;

public:
    UpdateGameStatusAction(
            const GameState* gameState,
            const CoordsSet& criticalTileLocations,
            const SettingsGetter& settingsGetter,
            const bool atEndOfRound)
        : gameState(gameState),
          criticalTileLocations(criticalTileLocations),
          settingsGetter(settingsGetter),
          atEndOfRound(atEndOfRound) {}
};
}  // namespace shardok

#endif  // EAGLE0_UPDATEGAMESTATUSACTION_HPP
