from unittest import TestCase
from pygeai.core.utils.validators import sanitize_project_name


class TestSanitizeProjectName(TestCase):

    def test_sanitize_project_name_with_at_symbol(self):
        result = sanitize_project_name("Project@2024")
        self.assertEqual(result, "Project_2024")

    def test_sanitize_project_name_with_hash_symbol(self):
        result = sanitize_project_name("Project#1")
        self.assertEqual(result, "Project_1")

    def test_sanitize_project_name_with_parentheses(self):
        result = sanitize_project_name("Project (Copy)")
        self.assertEqual(result, "Project _Copy")

    def test_sanitize_project_name_with_ampersand(self):
        result = sanitize_project_name("Test & Development")
        self.assertEqual(result, "Test _ Development")

    def test_sanitize_project_name_with_multiple_special_chars(self):
        result = sanitize_project_name("Project@Domain.com")
        self.assertEqual(result, "Project_Domain_com")

    def test_sanitize_project_name_valid_name_unchanged(self):
        result = sanitize_project_name("Valid_Project-Name")
        self.assertEqual(result, "Valid_Project-Name")

    def test_sanitize_project_name_with_spaces_unchanged(self):
        result = sanitize_project_name("My Project")
        self.assertEqual(result, "My Project")

    def test_sanitize_project_name_collapse_multiple_underscores(self):
        result = sanitize_project_name("Project__With___Multiple____Underscores")
        self.assertEqual(result, "Project_With_Multiple_Underscores")

    def test_sanitize_project_name_strip_leading_underscores(self):
        result = sanitize_project_name("___Leading")
        self.assertEqual(result, "Leading")

    def test_sanitize_project_name_strip_trailing_underscores(self):
        result = sanitize_project_name("Trailing___")
        self.assertEqual(result, "Trailing")

    def test_sanitize_project_name_strip_leading_and_trailing_underscores(self):
        result = sanitize_project_name("___Both___")
        self.assertEqual(result, "Both")

    def test_sanitize_project_name_empty_string(self):
        result = sanitize_project_name("")
        self.assertEqual(result, "")

    def test_sanitize_project_name_none(self):
        result = sanitize_project_name(None)
        self.assertIsNone(result)

    def test_sanitize_project_name_with_exclamation(self):
        result = sanitize_project_name("Project!")
        self.assertEqual(result, "Project")

    def test_sanitize_project_name_with_brackets(self):
        result = sanitize_project_name("Test [with] {brackets}")
        self.assertEqual(result, "Test _with_ _brackets")

    def test_sanitize_project_name_alphanumeric_only(self):
        result = sanitize_project_name("Test123Project456")
        self.assertEqual(result, "Test123Project456")

    def test_sanitize_project_name_with_accents(self):
        result = sanitize_project_name("válid name with accents")
        self.assertEqual(result, "v_lid name with accents")

    def test_sanitize_project_name_complex_case(self):
        result = sanitize_project_name("Project@#$%^&*()")
        self.assertEqual(result, "Project")
