#include "torlinkc/engine/types.hpp"

namespace torlinkc {

std::string downloadStatusToString(DownloadStatus s) {
  switch (s) {
    case DownloadStatus::Downloading:
      return "downloading";
    case DownloadStatus::Queued:
      return "queued";
    case DownloadStatus::Paused:
      return "paused";
    case DownloadStatus::Completed:
      return "completed";
    case DownloadStatus::Failed:
      return "failed";
  }
  return "downloading";
}

std::string seedStatusToString(SeedStatus s) {
  switch (s) {
    case SeedStatus::Seeding:
      return "seeding";
    case SeedStatus::Paused:
      return "paused";
    case SeedStatus::Missing:
      return "missing";
  }
  return "seeding";
}

std::optional<DownloadStatus> downloadStatusFromString(const std::string& s) {
  if (s == "downloading") return DownloadStatus::Downloading;
  if (s == "queued") return DownloadStatus::Queued;
  if (s == "paused") return DownloadStatus::Paused;
  if (s == "completed") return DownloadStatus::Completed;
  if (s == "failed") return DownloadStatus::Failed;
  return std::nullopt;
}

std::optional<SeedStatus> seedStatusFromString(const std::string& s) {
  if (s == "seeding") return SeedStatus::Seeding;
  if (s == "paused") return SeedStatus::Paused;
  if (s == "missing") return SeedStatus::Missing;
  return std::nullopt;
}

}  // namespace torlinkc
