#include "Ship/Vulnerable.h"

#include <Core/Time.h>

#include <assert.h>

Vulnerable::Vulnerable(std::unique_ptr<Cargo>&& cargo, Time* time, int durability, int maxDurability)
    : DecoratedCargo(std::move(cargo)), _time(time), _durability(durability), _maxDurability(maxDurability) {
    assert(_time);
    time->attach(this);
}

// Rule of 5
Vulnerable::~Vulnerable() {
    _time->detach(this);
}

void Vulnerable::nextDay() {
    _durability = std::max(0, _durability - 1);
}

size_t Vulnerable::getPrice() const {
    return (_durability * cargo().getPrice()) / _maxDurability;
}

const std::string& Vulnerable::name() const {
    return cargo().name();
}

void Vulnerable::accept(const CargoDamageVisitor& visitor) {
    cargo().accept(visitor);
}