#pragma once

#include <vector>
#include <queue>

#include "Core/Core.h"
#include "Core/Singleton.h"

class ImageBuffer : public Singleton<ImageBuffer> {
public:
    enum class IBType {
        Human,
        Face,
        FaceMask,
    };
public:
    explicit ImageBuffer() noexcept = default;
    ~ImageBuffer() = default;

    ImageBuffer(const ImageBuffer&) = delete;
    ImageBuffer& operator=(const ImageBuffer&) = delete;

    bool Initialize() override;
    void Uninitialize() override;

    void PushImage(IBType type, std::vector<uint8> data, uint32 width, uint32 height, uint32 comp);
    void Update(IBType type, class Texture2D* texture);

private:
    void PushHumanImage(std::vector<uint8> data, uint32 width, uint32 height, uint32 comp);
    void UpdateHuman(class Texture2D* texture);

    void PushFaceImage(std::vector<uint8> data, uint32 width, uint32 height, uint32 comp);
    void UpdateFace(class Texture2D* texture);
    void PushFaceMaskImage(std::vector<uint8> data, uint32 width, uint32 height, uint32 comp);
    void UpdateFaceMask(class Texture2D* texture);

private:
    struct Image {
        std::vector<uint8> data;
        uint32 width;
        uint32 height;
        uint32 comp;
        bool updated{false};
    };
    CriticalSection human_cs_;
    Image human_;

    CriticalSection face_cs_;
    Image face_;

    CriticalSection face_mask_cs_;
    Image faceMask_;
    

};
