#include <doctest/doctest.h>

#include "torlinkc/sources/registry.hpp"

using namespace torlinkc;

TEST_CASE("allSources returns all 10 sources in registry order") {
  const auto sources = allSources();
  REQUIRE(sources.size() == 10);
  CHECK(sources[0].id == "fitgirl");
  CHECK(sources[1].id == "yts");
  CHECK(sources[2].id == "tpb-movies");
  CHECK(sources[3].id == "x1337-movies");
  CHECK(sources[4].id == "eztv");
  CHECK(sources[5].id == "tpb-tv");
  CHECK(sources[6].id == "x1337-tv");
  CHECK(sources[7].id == "nyaa");
  CHECK(sources[8].id == "subsplease");
  CHECK(sources[9].id == "bittorrented");
}

TEST_CASE("only fitgirl and subsplease report no swarm health") {
  for (const auto& s : allSources()) {
    const bool expectHealth = s.id != "fitgirl" && s.id != "subsplease";
    CHECK(s.reportsHealth == expectHealth);
  }
}

TEST_CASE("sourceById maps every source id back to itself") {
  const auto byId = sourceById();
  REQUIRE(byId.size() == 10);
  for (const auto& s : allSources()) {
    REQUIRE(byId.count(s.id) == 1);
    CHECK(byId.at(s.id).label == s.label);
  }
}

TEST_CASE("sourceInCategory: All matches every source") {
  for (const auto& s : allSources()) CHECK(sourceInCategory(s, Category::All));
}

TEST_CASE("sourceInCategory respects each source's declared groups") {
  const auto byId = sourceById();
  CHECK(sourceInCategory(byId.at("fitgirl"), Category::Games));
  CHECK_FALSE(sourceInCategory(byId.at("fitgirl"), Category::Movies));
  CHECK(sourceInCategory(byId.at("bittorrented"), Category::Movies));
  CHECK(sourceInCategory(byId.at("bittorrented"), Category::TV));
  CHECK_FALSE(sourceInCategory(byId.at("bittorrented"), Category::Anime));
  CHECK(sourceInCategory(byId.at("nyaa"), Category::Anime));
}

TEST_CASE("categoryLabel names match the UI's expected strings") {
  CHECK(categoryLabel(Category::All) == "All");
  CHECK(categoryLabel(Category::Games) == "Games");
  CHECK(categoryLabel(Category::Movies) == "Movies");
  CHECK(categoryLabel(Category::TV) == "TV");
  CHECK(categoryLabel(Category::Anime) == "Anime");
}
