#include "Ship/ShipBuilder.h"

#include "Ship/ShipEasyDifficultLvlStrategy.h"

#include <Core/PrettyPrintVisitor.h>
#include <iostream>

ShipBuilder::ShipBuilder()
    : _ship(std::make_unique<Ship>()) {
    _ship->_strategy = std::make_unique<ShipEasyDifficultLvlStrategy>();
    _ship->_visitor = std::make_unique<PrettyPrintVisitor>();
}

std::unique_ptr<Ship> ShipBuilder::build() {
    if (!_ship) {
        std::cout << "Builder may be use once\n";
        return nullptr;
    }

    // Check mandatory fields
    if (!_ship->_time || _ship->_name.empty() || _ship->_capacity == -1) {
        std::cout << "Mandatory fields are not set!\n";
        return nullptr;
    }

    _ship->initialize();
    return std::move(_ship);
}

ShipBuilder& ShipBuilder::setTime(Time* time) {
    _ship->_time = time;
    return *this;
}

ShipBuilder& ShipBuilder::setStrategy(std::unique_ptr<DifficultLvlStrategy<Ship, bool>> strategy) {
    _ship->_strategy = std::move(strategy);
    return *this;
}

ShipBuilder& ShipBuilder::setName(const std::string& name) {
    _ship->_name = name;
    return *this;
}

ShipBuilder& ShipBuilder::setCapacity(int capacity) {
    _ship->_capacity = capacity;
    return *this;
}

ShipBuilder& ShipBuilder::setCrew(int crew) {
    _ship->_crew = crew;
    return *this;
}

ShipBuilder& ShipBuilder::setVisitor(std::unique_ptr<PrintVisitor> visitor) {
    _ship->_visitor = std::move(visitor);
    return *this;
}

ShipBuilder& ShipBuilder::setArmor(int armor) {
    _ship->_armor = armor;
    return *this;
}

ShipBuilder& ShipBuilder::setDurability(int durability) {
    _ship->_durability = durability;
    return *this;
}
