"""
Bankgiro Number Normalizer

Normalizes Swedish Bankgiro account numbers.
"""

from .base import BaseNormalizer
from shared.utils.format_variants import FormatVariants
from shared.utils.text_cleaner import TextCleaner


class BankgiroNormalizer(BaseNormalizer):
    """
    Normalizes Bankgiro numbers.

    Generates format variants and OCR error variants.

    Examples:
        '5393-9484' -> ['5393-9484', '53939484', ...]
        '53939484' -> ['53939484', '5393-9484', ...]
    """

    def normalize(self, value: str) -> list[str]:
        """Generate variants of Bankgiro number."""
        # Use shared module for base variants
        variants = set(FormatVariants.bankgiro_variants(value))

        # Add OCR error variants
        digits = TextCleaner.extract_digits(value, apply_ocr_correction=False)
        if digits:
            for ocr_var in TextCleaner.generate_ocr_variants(digits):
                variants.add(ocr_var)

        return list(v for v in variants if v)
