#ifndef DEVICE_CTRL_YTJ_H
#define DEVICE_CTRL_YTJ_H

#include "ytj_barrier.h"
#include "ytj_vidicon.h"
#include "mqtt/mqtt_cli.h"
#include "wbs/ytj/ytj_config.pb.h"

namespace zsy
{
    struct RecognizeData
    {
        std::string id;
        std::string sn;
        std::string stationSn;
        bool front;
        std::string groupSn;
        std::string barrierSn;
        std::string licensePlate;
        std::string image;
    };

    inline void to_json(nlohmann::json &j, const RecognizeData &o)
    {
        j = nlohmann::json{
            {"id", o.id},
            {"sn", o.sn},
            {"stationSn", o.stationSn},
            {"front", o.front},
            {"groupSn", o.groupSn},
            {"barrierSn", o.barrierSn},
            {"licensePlate", o.licensePlate},
            {"image", o.image}
        };
    }

    class Ytj : public QObject
    {
        Q_OBJECT
        YtjConfig config;

        std::shared_ptr<YtjBarrier> barrier;

        std::shared_ptr<YtjVidicon> vidicon;

    private
        Q_SLOTS:
        

        void onRecognizeComplete(bool success, std::string id, std::string licensePlate, std::string image);

    public:
        explicit Ytj(YtjConfig config);

        ~Ytj() override = default;

        /**
         * 获取设备编号
         *
         * @return 设备编号
         */
        std::string sn() const;

        /**
         * 获取设备名称
         *
         * @return 设备名称
         */
        std::string name() const;

        /**
         * 打开道闸
         */
        void open(const std::string &id = "");

        /**
         * 拍照
         *
         * @return 照片内容
         */
        std::string photograph();
    };
} // zsy

#endif //DEVICE_CTRL_YTJ_H