#pragma once

#include <dbus/api/api.h>
#include <sdi_toolBox/generic/uuid.h>

namespace api::requirement
{
//--------------------------------------------------------------
struct Requirement
{
  std::string              uuid;
  std::string              parent_uuid;
  std::string              id;
  std::string              type;
  std::string              name;
  std::string              description;
  std::vector<Requirement> sub_requirements;

  /* Default constructor */
  Requirement()
  {
    uuid = sdi_toolBox::generic::UuidGenerator::uuid_v4();     // Generate a unique UUID for the requirement
  }
};
//--------------------------------------------------------------

/* --- */

//--------------------------------------------------------------
// Post event structs
//--------------------------------------------------------------
struct RequirementEvent : dBus::api::DefaultData<dBus::makeID("requirement.requirementEvent")>
{
  virtual ~RequirementEvent() = default;     // Default destructor

  Requirement requirementData;

  [[nodiscard]] std::string toString() const override
  {
    return std::format("RequirementEvent: id={}, name={}, subRequirementsCount={}",
                       requirementData.id,
                       requirementData.name,
                       requirementData.description,
                       requirementData.sub_requirements.size());
  }
};
//--------------------------------------------------------------

/* --- */

//--------------------------------------------------------------
// Post event helpers
//--------------------------------------------------------------
/* Post a requirement event to the bus. This function will post a
 * RequirementEvent containing the provided requirement data to the
 * bus, and return a PostReturnStatus indicating whether the post was
 * successful or if there were any issues (e.g., no subscribers,
 * timeout, etc.). */
inline dBus::api::PostReturnStatus postRequirementRequest(dBus::Bus  &bus,
                                                          Requirement requirement)
{
  auto eventData            = RequirementEvent();
  eventData.requirementData = std::move(requirement);

  return dBus::api::requestData<decltype(eventData), void>(bus, eventData.getID(), eventData, dBus::MessageCategory::UI);
}
//--------------------------------------------------------------
}     // namespace api::requirement
