#include <Machine/MDynamo/MDynamo.hpp>
#include <MachineComponent/AttributionComponent/AttributionComponent.hpp>
#include <MachineComponent/ElectricComponent/ElectricComponent.hpp>
#include <Milestone/ElectronicsMilestone/ElectronicsMilestone.hpp>

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

void MDynamo::recharge()
{
    getComponent<ElectricComponent>().rechargeBy(energyPerClick, energyPerClick);
}

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

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

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

bool MDynamo::canDrainEnergyFromSide(Side side)
{
    return side == Side::Bottom;
}

void MDynamo::onEnergyDrained(int amount)
{
    getComponent<AttributionComponent>().grantAchievementFor(
        std::string(Machine::Action::Placed),
        ElectronicsMilestone::ID, ElectronicsMilestone::GenerateDynamoEnergy
    );
}