#include <Machine/MIncinerator/MIncinerator.hpp>
#include <MachineComponent/ElectricComponent/ElectricComponent.hpp>
#include <World/LocalWorld/LocalWorld.hpp>
#include <Block/SpriteBlock/BasicBlock/Incinerator/Incinerator.hpp>
#include <Block/SpriteBlock/ConveyorBelt/ConveyorBelt.hpp>
#include <MachineComponent/BeltComponent/BeltComponent.hpp>
#include <Belt/Belt.hpp>

MIncinerator::MIncinerator(LocalWorld &world, glm::ivec3 pos) : Machine(world, pos)
{
    attach<ElectricComponent>();
    attach<BeltComponent>();
}

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

void MIncinerator::deserializeState(const uint8_t *data, size_t size)
{
    // NOP
}

bool MIncinerator::canConnectElectricWire(Side side)
{
    return side == Side::Bottom;
}

void MIncinerator::onItemStackEntering(Side side, ItemStack &stack)
{
    ElectricComponent &electricComp = getComponent<ElectricComponent>();

    electricComp.rechargeFrom(Side::Bottom, energyPerItem);
    if (!electricComp.tryConsume(energyPerItem))
    {
        return;
    }

    stack = ItemStack();
    m_world.playSound(Sound::incinerate, pos);
}