/*
* 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
*
* */

#include <gtest/gtest.h>
#include <ls-std/ls-std-core.hpp>
#include <ls-std/ls-std-event.hpp>

using ls::standard::core::IllegalArgumentException;
using ls::standard::event::Event;
using ls::standard::event::EventManager;
using ::std::make_shared;
using testing::Test;

namespace
{
  class EventTest : public Test
  {
    public:

      EventTest() = default;
      ~EventTest() override = default;
  };

  TEST_F(EventTest, getClassName)
  {
    ASSERT_STREQ("OnClickEvent", Event("OnClickEvent").getClassName().c_str());
  }

  TEST_F(EventTest, getManager)
  {
    ASSERT_TRUE(Event("TmpEvent").getManager() == nullptr);
  }

  TEST_F(EventTest, of)
  {
    const auto event = Event("TmpEvent").supervisedBy(make_shared<EventManager>());

    ASSERT_STREQ("TmpEvent", event.getClassName().c_str());
    ASSERT_TRUE(event.getManager() != nullptr);
  }

  TEST_F(EventTest, of_with_no_reference)
  {
    EXPECT_THROW(
        {
          try
          {
            auto event = Event("TmpEvent").supervisedBy(nullptr);
          }
          catch (const IllegalArgumentException &_exception)
          {
            throw;
          }
        },
        IllegalArgumentException);
  }

  TEST_F(EventTest, setManager)
  {
    auto event = Event("TmpEvent");
    ASSERT_TRUE(event.getManager() == nullptr);

    event.setManager(make_shared<EventManager>());
    ASSERT_FALSE(event.getManager() == nullptr);
  }

  TEST_F(EventTest, setManager_with_no_reference)
  {
    auto event = Event("TmpEvent");

    EXPECT_THROW(
        {
          try
          {
            event.setManager(nullptr);
          }
          catch (const IllegalArgumentException &_exception)
          {
            throw;
          }
        },
        IllegalArgumentException);
  }
}
