"""
Tests for InvoiceNumberNormalizer

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

import pytest
from shared.normalize.normalizers.invoice_number_normalizer import InvoiceNumberNormalizer


class TestInvoiceNumberNormalizer:
    """Test InvoiceNumberNormalizer functionality"""

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

    def test_pure_digits(self, normalizer):
        """Pure digit invoice number should return as-is"""
        result = normalizer.normalize('100017500321')
        assert '100017500321' in result
        assert len(result) == 1

    def test_with_prefix(self, normalizer):
        """Invoice number with prefix should extract digits and keep original"""
        result = normalizer.normalize('INV-100017500321')
        assert 'INV-100017500321' in result
        assert '100017500321' in result
        assert len(result) == 2

    def test_alphanumeric(self, normalizer):
        """Alphanumeric invoice number should extract digits"""
        result = normalizer.normalize('ABC123XYZ456')
        assert 'ABC123XYZ456' in result
        assert '123456' in result

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

    def test_whitespace_only(self, normalizer):
        """Whitespace-only 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('INV-12345')
        assert 'INV-12345' in result
        assert '12345' in result

    def test_with_special_characters(self, normalizer):
        """Invoice number with special characters should be normalized"""
        result = normalizer.normalize('INV/2025/00123')
        assert 'INV/2025/00123' in result
        assert '202500123' in result

    def test_unicode_normalization(self, normalizer):
        """Unicode zero-width characters should be removed"""
        result = normalizer.normalize('INV\u200b123\u200c456')
        assert 'INV123456' in result
        assert '123456' in result

    def test_multiple_dashes(self, normalizer):
        """Invoice number with multiple dashes should be normalized"""
        result = normalizer.normalize('INV-2025-001-234')
        assert 'INV-2025-001-234' in result
        assert '2025001234' in result

    def test_no_digits(self, normalizer):
        """Invoice number with no digits should return original only"""
        result = normalizer.normalize('ABCDEF')
        assert 'ABCDEF' in result
        assert len(result) == 1

    def test_digits_only_variant_not_duplicated(self, normalizer):
        """Digits-only variant should not be duplicated if same as original"""
        result = normalizer.normalize('12345')
        assert result == ['12345']
