#pragma once

#include <atomic>
#include <chrono>
#include <memory>
#include <vector>

#include <QHash>
#include <QString>

#include "core/memory/MemoryPool.h"
#include "core/plugin_system/IProtocolFramerPlugin.h"

namespace softbus::message_bus::pipeline::protocol::modbusrtu
{

struct ModbusRtuFramerPluginConfig
{
    std::size_t maxAdu{256};
    int interFrameTimeoutMs{0};
};

class ModbusRtuFramerPlugin final : public softbus::core::plugin_system::IProtocolFramerPlugin
{
public:
    explicit ModbusRtuFramerPlugin(std::shared_ptr<softbus::core::memory::MemoryPool> pool,
                                   ModbusRtuFramerPluginConfig cfg = {});

    QString pluginId() const override;
    bool supports(const QString& protocolHint) const override;
    void bindMemoryPool(std::shared_ptr<softbus::core::memory::MemoryPool> pool) override;
    std::unique_ptr<softbus::core::plugin_system::IProtocolFramerSession> createFramerSession(
        const QString& endpoint, const QJsonObject& params) override;

private:
    std::shared_ptr<softbus::core::memory::MemoryPool> m_pool;
    ModbusRtuFramerPluginConfig m_cfg;
};

std::shared_ptr<softbus::core::plugin_system::IProtocolFramerPlugin> makeModbusRtuFramerPlugin(
    std::shared_ptr<softbus::core::memory::MemoryPool> pool, ModbusRtuFramerPluginConfig cfg = {});
softbus::core::plugin_system::IProtocolFramerPlugin* createModbusRtuFramerPluginRaw();

} // namespace softbus::message_bus::pipeline::protocol::modbusrtu
