#ifndef BARRIER_VIDICON_H
#define BARRIER_VIDICON_H
#include "vidicon.h"
#include "vidicon_properties.h"
#include "nlohmann/json.hpp"
#include <atomic>

namespace zsy
{
    struct PhotographResult
    {
        struct Payload
        {
            std::string image_content;
        };

        Payload payload;
    };

    inline void from_json(const nlohmann::json &j, PhotographResult::Payload &o)
    {
        PARSE_JSON(image_content, o.image_content);
    }

    inline void from_json(const nlohmann::json &j, PhotographResult &o)
    {
        PARSE_JSON(payload, o.payload);
    }


    class BarrierVidicon : public Vidicon
    {
        VidiconProperties config;
        std::atomic<bool> hasNewContent;
        std::string imageContent;

        void saveImageToFile(const std::string &decodedImageData, const std::string &filePath);

    public:
        ~BarrierVidicon() override;

        explicit BarrierVidicon(const VidiconProperties &config);

        std::shared_ptr<std::istream> photograph() override;
    };
}

#endif //BARRIER_VIDICON_H
