#ifndef MCOMBUSTION_GENERATOR_HPP_
#define MCOMBUSTION_GENERATOR_HPP_

#include <vector>
#include <cstdint>

#include <Machine/Machine.hpp>
#include <ItemStack/ItemStack.hpp>
#include <Item/IInventory.hpp>
#include <Machine/IFluidMachine.hpp>
#include <Machine/IElectricMachine.hpp>

/**
 * @brief The combustion generator machine.
 */
class MCombustionGenerator :
    public Machine,
    public IInventory,
    public IFluidMachine,
    public IElectricMachine
{
private:
    std::vector<ItemStack> stacks;
    bool isSwitchedOnPriv;

    ItemStack& petrolSlot();
    ItemStack& rechargeSlot();
    Side getOutputSide();

public:
    static constexpr int fluidCapacity = 20000;
    static constexpr int energyCapacity = 1000;
    static constexpr int powerOutput = 70;
    static constexpr int fuelUsage = 2;

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

    /**
     * @brief Returns true if the generator is switched on/
     */
    bool isSwitchedOn();

    /**
     * @brief Set whether the combustion generator is on.
     */
    void setSwitch(bool on);

    /**
     * @brief Return the current level of petrol (ml).
     */
    int getPetrolLevel();

    /**
     * @brief Return the current amount of energy stored (J).
     */
    int getStoredEnergy();

    virtual void serializeState(std::vector<uint8_t> &outBytes) override;
    virtual void deserializeState(const uint8_t *data, size_t size) 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 canConnectFluidPipe(Side side) override;
    virtual int getMaxFluidToAccept(std::optional<Side> side, std::string fluidName) override;
    virtual bool canConnectElectricWire(Side side) override;
    virtual bool canDrainEnergyFromSide(Side side) override;
    virtual void saveMainConfig(MachineConfig &config) override;
    virtual void loadMainConfig(const MachineConfig &config, bool consumed) override;
};

#endif
