"""
Tests for OrganisationNumberNormalizer

Usage:
    pytest tests/normalize/normalizers/test_organisation_number_normalizer.py -v
"""

import pytest
from shared.normalize.normalizers.organisation_number_normalizer import OrganisationNumberNormalizer


class TestOrganisationNumberNormalizer:
    """Test OrganisationNumberNormalizer functionality"""

    @pytest.fixture
    def normalizer(self):
        """Create normalizer instance for testing"""
        return OrganisationNumberNormalizer()

    def test_with_dash(self, normalizer):
        """Organisation number with dash should generate variants"""
        result = normalizer.normalize('556123-4567')
        assert '556123-4567' in result
        assert '5561234567' in result

    def test_without_dash(self, normalizer):
        """Organisation number without dash should generate dash variant"""
        result = normalizer.normalize('5561234567')
        assert '5561234567' in result
        assert '556123-4567' in result

    def test_from_vat_number(self, normalizer):
        """VAT number should extract organisation number"""
        result = normalizer.normalize('SE556123456701')
        assert '5561234567' in result
        assert '556123-4567' in result
        assert 'SE556123456701' in result

    def test_vat_variants(self, normalizer):
        """Organisation number should generate VAT number variants"""
        result = normalizer.normalize('556123-4567')
        assert 'SE556123456701' in result
        # With spaces
        vat_with_spaces = [v for v in result if 'SE' in v and ' ' in v]
        assert len(vat_with_spaces) > 0

    def test_12_digit_with_century(self, normalizer):
        """12-digit organisation number with century should be handled"""
        result = normalizer.normalize('165561234567')
        assert '5561234567' in result
        assert '556123-4567' in result

    def test_empty_string(self, normalizer):
        """Empty string should return empty list"""
        result = normalizer('')
        assert result == []

    def test_none_value(self, normalizer):
        """None value should return empty list"""
        result = normalizer(None)
        assert result == []

    def test_callable_interface(self, normalizer):
        """Normalizer should be callable via __call__"""
        result = normalizer('556123-4567')
        assert '5561234567' in result

    def test_vat_with_spaces(self, normalizer):
        """VAT number with spaces should be normalized"""
        result = normalizer.normalize('SE 556123-4567 01')
        assert '5561234567' in result
        assert 'SE556123456701' in result

    def test_mixed_case_vat_prefix(self, normalizer):
        """Mixed case VAT prefix should be normalized"""
        result = normalizer.normalize('se556123456701')
        assert 'SE556123456701' in result

    def test_generates_ocr_variants(self, normalizer):
        """Should generate OCR error variants"""
        result = normalizer.normalize('556123-4567')
        # Should contain multiple variants including OCR corrections
        assert len(result) > 5
