"""
Plusgiro Number Normalizer

Normalizes Swedish Plusgiro account numbers.
"""

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


class PlusgiroNormalizer(BaseNormalizer):
    """
    Normalizes Plusgiro numbers.

    Generates format variants and OCR error variants.

    Examples:
        '1234567-8' -> ['1234567-8', '12345678', ...]
        '12345678' -> ['12345678', '1234567-8', ...]
    """

    def normalize(self, value: str) -> list[str]:
        """Generate variants of Plusgiro number."""
        # Use shared module for base variants
        variants = set(FormatVariants.plusgiro_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)
