"""
脱敏处理器基类
"""

import re
from abc import ABC, abstractmethod
from typing import Any, Dict


class BaseDesensitizer(ABC):
    """脱敏处理器基类"""

    def __init__(self):
        self.patterns: Dict[str, re.Pattern] = {}
        self._compile_patterns()

    @abstractmethod
    def _compile_patterns(self):
        """编译正则表达式模式"""
        pass

    @abstractmethod
    def process(self, content: str, registry: Any, strict_mode: bool = False) -> str:
        """处理内容并返回脱敏后的文本

        Args:
            content: 输入文本
            registry: 实体注册表
            strict_mode: 严格模式（用于方案B的后校验阶段）

        Returns:
            脱敏后的文本
        """
        pass

    def _replace_with_placeholder(self, content: str, pattern: re.Pattern,
                                   placeholder: str, registry: Any = None) -> str:
        """通用替换方法"""
        return pattern.sub(placeholder, content)
