#pragma once

#include "pahoc/mqtt_async.h"
#include "message/unpacket.hpp"
#include <pcl/point_types.h>
#include <pcl/point_cloud.h>

class RslidarMqttAsyncClient : public MqttAsyncClient {
public:
    RslidarMqttAsyncClient() = default;

    void init();

    bool setCloudData(const std::string &topic, pcl::PointCloud<pcl::PointALL>::Ptr &cloud);

    bool getCloudData(const std::string &topic, pcl::PointCloud<pcl::PointXYZI>::Ptr &cloud);

    bool getCloudData(const std::string &topic, pcl::PointCloud<pcl::PointXYZ>::Ptr &cloud);

    bool getCloudData(const std::string &topic, pcl::PointCloud<pcl::PointXYZRGB>::Ptr &cloud, double *color);

private:
    static int CloudDataArrived(MqttAsyncClient *client, char *topicName, int topicLen, MQTTAsync_message *message);

public:

private:
    std::mutex m_cloud_mutex;
    std::map<std::string, int> m_topics_;
    std::map<std::string, pcl::PointCloud<pcl::PointALL>::Ptr> m_cloud_;
    std::map<std::string, pcl::PointCloud<pcl::PointALL>::Ptr> m_full_cloud_;
    std::map<std::string, std::chrono::steady_clock::time_point> m_topic_time_;
};
