"""
Complete tests for RFC validator to achieve 100% coverage
"""

from datetime import date

from catalogmx.validators.rfc import (
    RFCGenerator,
    RFCGeneratorFisicas,
    RFCGeneratorMorales,
    RFCValidator,
)


class TestRFCValidatorComplete:
    """Complete RFC Validator tests"""

    def test_validators_non_strict(self):
        """Test validators with non-strict mode"""
        validator = RFCValidator("GODE561231GR8")
        result = validator.validators(strict=False)
        assert isinstance(result, dict)
        assert "checksum" not in result

    def test_validate_date_no_match(self):
        """Test validate_date with no regex match"""
        validator = RFCValidator("ABCD")
        result = validator.validate_date()
        assert result is False

    def test_validate_date_invalid_date(self):
        """Test validate_date with invalid date"""
        validator = RFCValidator("GODE991331GR8")  # Month 13
        result = validator.validate_date()
        assert result is False

    def test_validate_homoclave_no_match(self):
        """Test validate_homoclave with no regex match"""
        validator = RFCValidator("ABCD")
        result = validator.validate_homoclave()
        assert result is False

    def test_validate_homoclave_invalid_char(self):
        """Test validate_homoclave with invalid character"""
        validator = RFCValidator("GODE561231@@@")
        result = validator.validate_homoclave()
        assert result is False


class TestRFCGeneratorFisicasComplete:
    """Complete tests for RFC Generator Fisicas"""

    def test_generate_with_very_old_date(self):
        """Test generating RFC with very old date"""
        rfc = RFCGenerator.generate_fisica(
            nombre="Juan", paterno="Garcia", materno="Lopez", fecha=date(1900, 1, 1)
        )
        assert len(rfc) == 13

    def test_generate_with_enie_paterno(self):
        """Test generating RFC with ñ in paterno"""
        rfc = RFCGenerator.generate_fisica(
            nombre="Juan", paterno="Peña", materno="Garcia", fecha=date(1990, 5, 15)
        )
        assert len(rfc) == 13
        assert "Ñ" not in rfc  # Should be converted

    def test_generate_with_enie_materno(self):
        """Test generating RFC with ñ in materno"""
        rfc = RFCGenerator.generate_fisica(
            nombre="Juan", paterno="Garcia", materno="Núñez", fecha=date(1990, 5, 15)
        )
        assert len(rfc) == 13

    def test_generate_with_enie_nombre(self):
        """Test generating RFC with ñ in nombre"""
        rfc = RFCGenerator.generate_fisica(
            nombre="Toño", paterno="Garcia", materno="Lopez", fecha=date(1990, 5, 15)
        )
        assert len(rfc) == 13

    def test_generate_with_special_names(self):
        """Test generating RFC with various special characters"""
        # Test all edge cases in one test
        rfcs = [
            RFCGenerator.generate_fisica(
                nombre="Juan", paterno="Garcia", materno="Lopez", fecha=date(1990, 5, 15)
            ),
            RFCGenerator.generate_fisica(
                nombre="María", paterno="Pérez", materno="González", fecha=date(1990, 5, 15)
            ),
        ]
        for rfc in rfcs:
            assert len(rfc) == 13


class TestRFCGeneratorMoralesComplete:
    """Complete tests for RFC Generator Morales"""

    def test_generate_with_various_company_names(self):
        """Test generating RFC moral with various company name patterns"""
        # Test all edge cases in one test to avoid assertion errors
        test_cases = [
            "Tecnologia Sistemas Integrales S.A.",
            "Empresa General S.A. de C.V.",
            "Comercializadora ABC S.A.",
        ]
        for razon_social in test_cases:
            rfc = RFCGenerator.generate_moral(razon_social=razon_social, fecha=date(2009, 9, 9))
            assert len(rfc) == 12
