#include "Store/Store.h"

#include <Core/PrintVisitor.h>

Store::Store(std::vector<std::unique_ptr<Cargo>>&& cargos, std::unique_ptr<PrintVisitor>&& visitor)
    : _seed(_rd()), _cargoes(std::move(cargos)), _visitor(std::move(visitor)) {}

std::random_device Store::_rd{};

void Store::nextDay() {
    std::uniform_int_distribution<int> dist(-50, 50);
    for (auto& cargo : _cargoes) {
        cargo->amount() += dist(_seed);
    }
}

size_t Store::getTotalPrice() const {
    size_t value{0};
    for (const auto& cargo : _cargoes) {
        value += cargo->getPrice();
    }

    return value;
}

const std::vector<std::unique_ptr<Cargo>>& Store::cargoes() const {
    return _cargoes;
}

std::vector<std::string> Store::getCargosName() const {
    std::vector<std::string> names;
    for (const auto& cargo : _cargoes) {
        names.push_back(cargo->name());
    }

    return names;
}

void Store::printCargo() const {
    _visitor->visit(*this);
}
