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

#include "Core/Time.h"
#include "Ship/Cargo.h"
#include "Ship/Ship.h"
#include "Store/Store.h"

int main() {
    Time time;

    std::vector<std::unique_ptr<Cargo>> cargoes;
    cargoes.push_back(std::make_unique<Alcohol>(1'000));
    cargoes.push_back(std::make_unique<Fruit>(1'000));
    cargoes.push_back(std::make_unique<Item>(1'000));
    auto store = std::unique_ptr<Store, std::function<void(Store*)>>(
        [&cargoes, &time]() {
         auto* store = new Store(std::move(cargoes));
         try {
            time.attach(store);
         } catch (...) {
            abort();
         }
         return store; }(),
        [&time](Store* store) {
            time.detach(store);
            delete store;
        });

    Ship ship(&time, "Black Widow", 1000, 40);
    ship.load(std::make_unique<Alcohol>(300));
    ship.load(std::make_unique<Fruit>(200));
    ship.load(std::make_unique<Fruit>(150));
    ship.printCargo();

    for (int i = 0; i < 10; ++i) {
        ++time;
        std::cout << "\nDAY: " << time.day() << "\n";
        // std::cout << "crew: " << ship.crew() << '\n';
        // ship.printCargo();
        store->printCargo();
    }
}
