#pragma once
#include <utility>

#include "Core/Base/SM_RingBuffer.h"
#include "Core/Serial/Serial_Coro.h"

#include "Core/Statistics/Frequency_Limit.h"
#include "Core/Statistics/Statistics.h"
#include "Core/transmit_protocol/core/statistics.h"

#include "Database.h"
#include "Local_Server/global_include.h"
#include "global.h"
#include "PlayBack.h"


// 这个函数专门装cpu密集函数 放到线程池去处理
class Data_Source_Handler : public DataBase
{
public:
    std::shared_ptr<SSR::Msg> create_msg(const std::string& packet);

    virtual void origin_data_transform_mode_data(std::string& origin_data){};
    virtual void before_handle_msg(std::shared_ptr<SSR::Mode_Msg>& msg){};

    virtual void handle_mode_s(std::shared_ptr<SSR::Mode_S_Msg> msg);
    void handle_HULC(const std::string& packet);
    void process_mode_acs_data(const std::string& mode_data);
    Mode_AC_Statistic_Data mode_ac_statistic;
    Mode_S_Statistic_Data  mode_s_statistic;
    Psc::Speed_Statistics read_speed;
    Psc::Value_Statistics value_statistics;
    ~Data_Source_Handler() override {};

    // 推送到 data_feed 相关代码
    void  push_to_feed(const std::shared_ptr<SSR::Msg> &msg);
    void refresh_data_feed_key_list();
    struct Cached_Source_Info {
        std::string key;
        Psc::Value_Statistics mode_s_cache_num;
        Psc::Value_Statistics mode_other_cache_num;
    };
    std::atomic<bool> need_refresh_data_feed_key_list = true;
    std::vector<Cached_Source_Info> cached_data_feed_key_list{};
    Psc::JSON get_all_connect_feed_status();
    Psc::JSON get_all_connect_feed();
    std::mutex cdf_mtx;
};


