#ifndef MPUMP_HPP_
#define MPUMP_HPP_

#include <optional>
#include <string>
#include <Machine/Machine.hpp>
#include <Machine/IFluidMachine.hpp>
#include <Machine/IElectricMachine.hpp>
#include <Side/Side.hpp>

class MPump final :
    public Machine,
    public IFluidMachine,
    public IElectricMachine
{
private:
    static constexpr int powerConsumption = 1;

    std::string bufferedFluidName;
    uint32_t pumpRate;
    uint32_t bufferedAmount;
    bool isSwitchedOnPriv;
    std::optional<std::string> fluidFilter;

    Side getInputSide();
    Side getOutputSide();
    Side getElectricInputSide();
    
    bool pumpIn();
    bool pumpOut();
    bool pump();

public:
    MPump(LocalWorld &world, glm::ivec3 pos);

    /**
     * @brief Return the amount of fluid buffered in the pump.
     */
    uint32_t getBufferedAmount();

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

    /**
     * @brief Set the pump switch.
     */
    void setSwitch(bool on);

    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 void update() override;
    virtual bool canConnectFluidPipe(Side side) override;
    virtual bool canConnectElectricWire(Side side) override;

    friend class PumpController;
};

#endif