#include <functional>
#include <iostream>
#include <memory>

#include "Battle/BattleField.h"
#include "Core/BasicPrintVisitor.h"
#include "Core/PrettyPrintVisitor.h"
#include "Core/Time.h"
#include "Player/Enemy.h"
#include "Player/EnemyEasyDifficultLvlStrategy.h"
#include "Player/EnemyHardDifficultLvlStrategy.h"
#include "Player/RealPlayer.h"
#include "Ship/Cargo.h"
#include "Ship/CargoDamageVisitor.h"
#include "Ship/Ship.h"
#include "Ship/ShipBuilder.h"
#include "Ship/ShipEasyDifficultLvlStrategy.h"
#include "Ship/ShipJsonBuilder.h"
#include "Ship/ShipHardDifficultLvlStrategy.h"
#include "Store/Store.h"

int main() {
    Time time;

    auto ship = ShipBuilder()
                    .setTime(&time)
                    .setName("Black Widow")
                    .setCapacity(2000)
                    .setCrew(20)
                    .setStrategy(std::make_unique<ShipHardDifficultLvlStrategy>())
                    .setVisitor(std::make_unique<PrettyPrintVisitor>())
                    .setArmor(1500)
                    .setDurability(1500)
                    .build();
    ship->load(std::make_unique<Alcohol>(300));
    ship->load(std::make_unique<Fruit>(200));
    ship->load(std::make_unique<Fruit>(150));
    RealPlayer user("Mateusz", std::move(ship));

    Enemy enemy("Enemy1",
                ShipJsonBuilder("../ships.json").buildGaleon(&time, "Queens Anne revenge"),
                std::make_unique<EnemyEasyDifficultLvlStrategy>(),
                CargoDamageVisitor{});

    BattleField battefield{&user, &enemy};
    while (true) {
        for (auto* player : battefield.players()) {
            std::cout << "-------------------------------------------------------------------\n";
            std::cout << "Player HP: " << user.getShip().durability() << "   ARMOR: " << user.getShip().armor() << "  |  ";
            std::cout << "Enemy HP: " << enemy.getShip().durability() << "   ARMOR: " << enemy.getShip().armor() << '\n';
            std::cout << "-------------------------------------------------------------------\n";
            for (size_t i = 0; i < 3; ++i) {
                const auto status = player->makeAction(battefield);
                if (status == Action::Status::Escaped || status == Action::Status::Defeated) {
                    return 0;
                }
            }
        }
    }
}
