#include "requirements.h"

#include <format>
#include <sdi_toolBox/common/utils/hash.h>
#include <sdi_toolBox/desktop/utils/uuid.h>

using namespace std;
using namespace core::requirements;
//--------------------------------------------------------------
/* Default constructor */
Requirement::Requirement()
{
  // Initialize fields with default values
  m_uuid = sdi_toolBox::desktop::utils::uuid::v7();
}
//--------------------------------------------------------------
/* Get a summary of the requirement for list display */
Requirement::json Requirement::get_summary()
{
  const json summary = {
    { "uuid", uuid },
    { "reference", format("REQ-{}", reference) },
    { "title", title },
    { "category", category },
    { "status", status_to_string(status) },
    { "priority", priority }
  };

  return summary;
}
//--------------------------------------------------------------
/* Get detailed information about the requirement for the detail view */
Requirement::json Requirement::get_detail()
{
  return {};
}
//--------------------------------------------------------------
/* Convert a Status enum value to a human-readable string */
std::string Requirement::status_to_string(const Status pStatus)
{
  switch (pStatus)
  {
    using enum Status;
    case Unknown:
      return "Unknown";
    case Draft:
      return "Draft";
    case InReview:
      return "InReview";
    case Approved:
      return "Approved";
    case Blocked:
      return "Blocked";
    case Delivered:
      return "Delivered";
  }

  return "InvalidStatus";
}
//--------------------------------------------------------------
/* Convert a human-readable string to a Status enum value */
Requirement::Status Requirement::string_to_status(const std::string &statusStr)
{
  using namespace sdi_toolBox::common::utils::hash;
  const auto hash = fnv1a(sv(statusStr));

  switch (hash)
  {
    case fnv1a(sv("Draft")):
      return Status::Draft;
    case fnv1a(sv("InReview")):
      return Status::InReview;
    case fnv1a(sv("Approved")):
      return Status::Approved;
    case fnv1a(sv("Blocked")):
      return Status::Blocked;
    case fnv1a(sv("Delivered")):
      return Status::Delivered;
    case fnv1a(sv("Unknown")):
    default:
      return Status::Unknown;
  }
}
//--------------------------------------------------------------
