#ifndef M_BARREL_HPP_
#define M_BARREL_HPP_

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

/**
 * @brief The barrel machine.
 */
class MBarrel : public Machine, public IInventory, public IFluidMachine
{
private:
    std::vector<ItemStack> stacks;

    bool canStoreFluid(std::string name);

public:
    /**
     * @brief The capacity of a barrel (in ml).
     */
    static const int capacity = 100000;

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

    /**
     * @brief Returns the internal name of the contained fluid, or the empty string if empty.
     */
    std::string getFluidName();

    /**
     * @brief Return the number of ml of fluid contained.
     */
    int getFluidAmount();

    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 int getMaxFluidToRelease(std::optional<Side> side, std::string fluidName) override;

    friend class BarrelController;
};

#endif