#ifndef MQUARTZ_CLOCK_HPP_
#define MQUARTZ_CLOCK_HPP_

#include <Machine/IDataMachine.hpp>
#include <array>
#include <cstdint>
#include <vector>
#include <Machine/Machine.hpp>
#include <ItemStack/ItemStack.hpp>
#include <Item/IInventory.hpp>
#include <Machine/IElectricMachine.hpp>

class MQuartzClock :
    public Machine,
    public IInventory,
    public IElectricMachine,
    public IDataMachine
{
private:
    static constexpr int powerConsumption = 4;

    std::vector<ItemStack> stacks;
    std::array<uint64_t, 4> periods = {};

    ItemStack& energySlot();

    Side getOutputSide();

public:
    static constexpr int energyCapacity = 1000;

    MQuartzClock(LocalWorld &world, glm::ivec3 pos);

    /**
     * @brief Get the energy stored (J).
     */
    int getEnergy();

    virtual void serializeState(std::vector<uint8_t> &outBytes) override;
    virtual void deserializeState(const uint8_t *data, size_t size) override;
    virtual void saveMainConfig(MachineConfig &config) override;
    virtual void loadMainConfig(const MachineConfig &config, bool consumed) override;
    virtual int getNumSlots() override;
    virtual ItemStack getStackInSlot(int slot) override;
    virtual void setStackInSlot(int slot, ItemStack stack) override;
    virtual bool isAllowedStackInSlot(int slot, ItemStack stack) override;
    virtual void update() override;
    virtual bool canConnectElectricWire(Side side) override;
    virtual Side getDataInputSide() override;
    virtual DataLink::ChannelBitmap getActiveChannels() override;

    friend class QuartzClockController;
};

#endif