#pragma once

#include "../level/entity.h"
#include "../interface/resourceProvider.h"
#include "pipe.h"
#include "../items.h"
#include <list>
#include <vector>
#include <mutex>

namespace game{

class plant: virtual public entity, virtual public resourceProvider, public selectable, public withGui
{
public:
    plant(const vec2u &position, level *root);
    ~plant() = default;

    virtual void update();
    virtual void draw();

    virtual void onNeighbourCreated(entity*);
    virtual void beforeNeighbourDestroyed(entity*);

    void addPipe(basicPipe*) noexcept;
    void addProvider(resourceProvider*) noexcept;

    void setReceipt(receiptInfo*);

    virtual void onGui() noexcept;

    virtual void select() noexcept;
    virtual void hover() noexcept;

    virtual float require(uint item, float amount) noexcept;
protected:
    std::list<resourceProvider*> _providers;
    std::list<basicPipe*> _pipes;
    receiptInfo *_receipt;

    uint32_t _receiptTicks;

    void _drawWindow();
    void _drawShortInfo();

    std::vector<productInfo> _input, _output;
    std::mutex _locker;
    bool _needShowGui, _needShowShortInfo;

    char _update();
    char _stat[0xFFFF];
    int _statPos;
};

}
