#include <MachineComponent/BeltComponent/BeltComponent.hpp>
#include <Machine/Machine.hpp>
#include <World/LocalWorld/LocalWorld.hpp>

std::string BeltComponent::tagName = "main:beltComponent";

BeltComponent::BeltComponent(Machine &machine) :
    MachineComponent(machine),
    machine(machine),
    beltMachine(dynamic_cast<IBeltMachine&>(machine))
{}

std::shared_ptr<Belt> BeltComponent::getOutputBelt(Side side)
{
    std::shared_ptr<Belt> &belt = outputBelts[side.asNumber()];
    if (belt == nullptr)
    {
        belt = machine.getWorld().beltManager.acquireOperationalBelt(machine.pos, side);
    }

    return belt;
}

void BeltComponent::serializeState(std::vector<uint8_t> &outBytes)
{
    // NOP
}

void BeltComponent::deserializeState(const uint8_t *bytes, size_t size)
{
    // NOP
}

void BeltComponent::onRemoving()
{
    machine.getWorld().beltManager.removeBeltSegment(machine.pos);
}