/*
 * SPDX-FileCopyrightText: 2025 Copyright contributors to the cppTango project
 *
 * SPDX-License-Identifier: LGPL-3.0-or-later
 */
#ifndef TANGO_CLIENT_NOTIFDEVENTCONSUMER_H
#define TANGO_CLIENT_NOTIFDEVENTCONSUMER_H

#include <tango/client/EventConsumer.h>
#include <tango/client/EventConsumerKeepAliveThread.h>
#include <tango/common/omnithread_wrapper.h>

#include <COS/CosNotification.hh>
#include <COS/CosNotifyChannelAdmin.hh>
#include <COS/CosNotifyComm.hh>

namespace Tango
{

/********************************************************************************
 *                                                                                 *
 *                         NotifdEventConsumer class                                *
 *                                                                                 *
 *******************************************************************************/

// NOLINTNEXTLINE(cppcoreguidelines-virtual-class-destructor)
class NotifdEventConsumer : public POA_CosNotifyComm::StructuredPushConsumer, public EventConsumer, public omni_thread
{
  public:
    NotifdEventConsumer(ApiUtil *ptr);

    void push_structured_event(const CosNotification::StructuredEvent &) override;
    void cleanup_EventChannel_map() override;

    void disconnect_structured_push_consumer() override;
    void offer_change(const CosNotification::EventTypeSeq &, const CosNotification::EventTypeSeq &) override;

    void query_event_system(std::ostream &os) override;
    void get_subscribed_event_ids(DeviceProxy *, std::vector<int> &) override;

    void get_subscription_command_name(std::string &cmd) override
    {
        cmd = "EventSubscriptionChange";
    }

    CORBA::ORB_var orb_;

  protected:
    void connect_event_channel(const std::string &, Database *, bool, DeviceData &) override;
    void connect_event_system(const std::string &,
                              const std::string &,
                              const std::string &e,
                              const std::vector<std::string> &,
                              const EvChanIte &,
                              EventCallBackStruct &,
                              DeviceData &,
                              size_t) override;

    void set_channel_type(EventChannelStruct &ecs) override
    {
        ecs.channel_type = NOTIFD;
    }

    void zmq_specific(DeviceData &, std::string &, DeviceProxy *, const std::string &) override { }

    ReceivedFromAdmin initialize_received_from_admin(const Tango::DevVarLongStringArray *pArray,
                                                     const std::string &local_callback_key,
                                                     const std::string &adm_name,
                                                     bool device_from_env_var) override;

  private:
    CosNotifyChannelAdmin::EventChannel_var eventChannel;
    CosNotifyChannelAdmin::ConsumerAdmin_var consumerAdmin;
    CosNotifyChannelAdmin::ProxyID proxyId;
    CosNotifyChannelAdmin::ProxySupplier_var proxySupplier;
    CosNotifyChannelAdmin::StructuredProxyPushSupplier_var structuredProxyPushSupplier;
    CosNotifyChannelAdmin::EventChannelFactory_var eventChannelFactory;

    void *run_undetached(void *arg) override;

    ~NotifdEventConsumer() override = default;
};

} // namespace Tango

#endif
