#ifndef BELT_MOTOR_COMPONENT_HPP_
#define BELT_MOTOR_COMPONENT_HPP_

#include <MachineComponent/MachineComponent.hpp>
#include <Belt/Belt.hpp>
#include <memory>

/**
 * @brief A machine component for powering belts.
 * 
 * You must attacht the `ElectricComponent` and the `BeltComponent` before attaching this.
 */
class BeltMotorComponent : public MachineComponent
{
private:
    uint64_t movementTicks = 0;

    void walkBranchingBelts(std::shared_ptr<Belt> belt, std::vector<std::shared_ptr<Belt>> &belts, int depth);

public:
    static constexpr int powerPerWeight = 1;
    static constexpr int maxBranchingDepth = 3;
    static constexpr uint64_t ticksPerVoxel = 6;

    static std::string tagName;

    BeltMotorComponent(Machine &machine);

    /**
     * @brief Try advancing the main belt and all branching belts. Returns true if the belt is active. 
     */
    bool tryAdvance(std::shared_ptr<Belt> mainBelt);

    virtual void serializeState(std::vector<uint8_t> &outBytes) override;
    virtual void deserializeState(const uint8_t *bytes, size_t size) override;
};

#endif