/*
* Author:          Patrick-Christopher Mattulat
* Co-Author:       Claude Sonnet 4.6 (LLM)
* Company:         Lynar Studios
* E-Mail:          webmaster@lynarstudios.com
* Created:         2024-05-16
* Changed:         2026-06-23
*
* */

#ifndef LS_STD_EVENT_LISTENER_HPP
#define LS_STD_EVENT_LISTENER_HPP

#include "Event.hpp"
#include "EventParameter.hpp"
#include <ls-std/core/Class.hpp>
#include <ls-std/event/type/EventTypes.hpp>
#include <ls-std/os/dynamic-goal.hpp>

/*
 * @doc: class(name: 'EventListener', package: 'event')
 * @doc: event.EventListener.description('An instance of this class can listen to any event. Usually, this class is used as base class of any class that must listen to an event.')
 * */

namespace ls::standard::event
{
  class LS_STD_DYNAMIC_GOAL EventListener : public ::std::enable_shared_from_this<EventListener>, public ls::standard::core::Class
  {
    public:

      explicit EventListener();
      ~EventListener() noexcept override;

      [[nodiscard]] ls::standard::event::type::listener_id getId() const;
      void setId(ls::standard::event::type::listener_id _id);
      void setParameter(const ls::standard::event::EventParameter &_parameter);
      [[maybe_unused]] bool subscribe(const ls::standard::event::Event &_event, const ls::standard::event::type::event_action &_action);
      [[maybe_unused]] bool unsubscribe(const ls::standard::event::Event &_event);

    protected:

      ls::standard::event::EventParameter parameter{};

    private:

      ls::standard::event::type::listener_id id{};

      void _requestListenerId(const ::std::shared_ptr<ls::standard::core::Class> &_manager);
      [[nodiscard]] bool _subscribe(const ls::standard::event::Event &_event, const ls::standard::event::type::event_action &_action);
      [[nodiscard]] bool _unsubscribe(const ls::standard::event::Event &_event);
  };
}

#endif
