"""
Invoice Number Normalizer

Normalizes invoice numbers for matching.
"""

import re
from .base import BaseNormalizer


class InvoiceNumberNormalizer(BaseNormalizer):
    """
    Normalizes invoice numbers.

    Keeps only digits for matching while preserving original format.

    Examples:
        '100017500321' -> ['100017500321']
        'INV-100017500321' -> ['100017500321', 'INV-100017500321']
    """

    def normalize(self, value: str) -> list[str]:
        """Generate variants of invoice number."""
        value = self.clean_text(value)
        digits_only = re.sub(r'\D', '', value)

        variants = [value]
        if digits_only and digits_only != value:
            variants.append(digits_only)

        return list(set(v for v in variants if v))
