from __future__ import annotations

import unittest

from mais_humana.catalog import HUMAN_NEEDS, HUMAN_PROFILES, PLATFORMS, categories_for_text, get_platform
from mais_humana.models import NeedCategory, clamp_score, maturity_from_score, merge_unique, slugify


class ModelCatalogTests(unittest.TestCase):
    def test_slugify_keeps_operational_identity_readable(self) -> None:
        self.assertEqual(slugify("Tudo Para IA / Mais Humana"), "tudo-para-ia-mais-humana")
        self.assertEqual(slugify("  Identity.Platform  "), "identity-platform")
        self.assertEqual(slugify("***"), "item")

    def test_score_helpers_are_bounded(self) -> None:
        self.assertEqual(clamp_score(-40), 0)
        self.assertEqual(clamp_score(104.4), 100)
        self.assertEqual(clamp_score(44.6), 45)
        self.assertEqual(maturity_from_score(0).value, "not_found")
        self.assertEqual(maturity_from_score(95).value, "auditable")

    def test_merge_unique_drops_empty_and_preserves_order(self) -> None:
        self.assertEqual(merge_unique(["a", "", "b", "a", " c "]), ("a", "b", "c"))

    def test_catalog_has_human_operational_breadth(self) -> None:
        self.assertGreaterEqual(len(HUMAN_PROFILES), 12)
        self.assertGreaterEqual(len(HUMAN_NEEDS), 8)
        self.assertEqual(len(PLATFORMS), 14)
        self.assertEqual(get_platform("identity").repo_name, "tudo-para-ia-identity-platform")

    def test_categories_for_text_detects_expected_domains(self) -> None:
        text = "BYOK credentialRef health readiness invoice support admin_ui panelReady"
        categories = set(categories_for_text(text))
        self.assertIn(NeedCategory.INTEGRATION, categories)
        self.assertIn(NeedCategory.SECURITY, categories)
        self.assertIn(NeedCategory.OBSERVABILITY, categories)
        self.assertIn(NeedCategory.FINANCE, categories)
        self.assertIn(NeedCategory.SUPPORT, categories)
        self.assertIn(NeedCategory.EXPERIENCE, categories)


if __name__ == "__main__":
    unittest.main()

