"""
Tests for SupplierAccountsNormalizer

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

import pytest
from shared.normalize.normalizers.supplier_accounts_normalizer import SupplierAccountsNormalizer


class TestSupplierAccountsNormalizer:
    """Test SupplierAccountsNormalizer functionality"""

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

    def test_single_plusgiro(self, normalizer):
        """Single Plusgiro account should generate variants"""
        result = normalizer.normalize('PG:48676043')
        assert 'PG:48676043' in result
        assert '48676043' in result
        assert '4867604-3' in result

    def test_single_bankgiro(self, normalizer):
        """Single Bankgiro account should generate variants"""
        result = normalizer.normalize('BG:5393-9484')
        assert 'BG:5393-9484' in result
        assert '5393-9484' in result
        assert '53939484' in result

    def test_multiple_accounts(self, normalizer):
        """Multiple accounts separated by | should be handled"""
        result = normalizer.normalize('PG:48676043 | PG:49128028 | PG:8915035')
        assert '48676043' in result
        assert '49128028' in result
        assert '8915035' in result

    def test_prefix_normalization(self, normalizer):
        """Prefix should be normalized to uppercase"""
        result = normalizer.normalize('pg:48676043')
        assert 'PG:48676043' in result

    def test_prefix_with_space(self, normalizer):
        """Prefix with space should be generated"""
        result = normalizer.normalize('PG:48676043')
        assert 'PG: 48676043' in result

    def test_empty_account_in_list(self, normalizer):
        """Empty accounts in list should be ignored"""
        result = normalizer.normalize('PG:48676043 | | PG:49128028')
        # Should not crash and should handle both valid accounts
        assert '48676043' in result
        assert '49128028' in result

    def test_account_without_prefix(self, normalizer):
        """Account without prefix should be handled"""
        result = normalizer.normalize('48676043')
        assert '48676043' in result
        assert '4867604-3' in result

    def test_7_digit_account(self, normalizer):
        """7-digit account should generate dash format"""
        result = normalizer.normalize('4867604')
        assert '4867604' in result
        assert '486760-4' in result

    def test_10_digit_account(self, normalizer):
        """10-digit account (org number format) should be handled"""
        result = normalizer.normalize('5561234567')
        assert '5561234567' in result
        assert '556123-4567' in result

    def test_mixed_format_accounts(self, normalizer):
        """Mixed format accounts should all be normalized"""
        result = normalizer.normalize('BG:5393-9484 | PG:48676043')
        assert '53939484' in result
        assert '48676043' 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('PG:48676043')
        assert '48676043' in result
