from __future__ import annotations

from typing import Any, Dict

SENSITIVE_CONFIG_KEYS = ("password", "secret", "token", "api_key", "apikey")
MASKED_VALUE = "********"


def sanitize_config_for_logs(value: Any) -> Any:
    if isinstance(value, dict):
        sanitized: Dict[Any, Any] = {}
        for key, item in value.items():
            if isinstance(key, str) and any(sensitive_key in key.lower() for sensitive_key in SENSITIVE_CONFIG_KEYS):
                sanitized[key] = MASKED_VALUE
            else:
                sanitized[key] = sanitize_config_for_logs(item)
        return sanitized

    if isinstance(value, (list, tuple)):
        return type(value)(sanitize_config_for_logs(item) for item in value)

    return value
