from typing import Any, Dict

# edited by glg


class DeviceRegistrationRetryPolicy:
    def resolve_probe_attempt_limit(self, config: Dict[str, Any] = None) -> int:
        cfg = config if isinstance(config, dict) else {}
        try:
            raw = int(cfg.get("device_registration_probe_retry_attempts", 1))
        except (TypeError, ValueError):
            raw = 1
        return max(1, min(raw, 3))

    def should_retry_probe_exception(self, attempt: int, max_attempts: int, _error: Exception = None) -> bool:
        return int(attempt or 0) < int(max_attempts or 1)

    def should_retry_probe_status(self, attempt: int, max_attempts: int, status_code) -> bool:
        if int(attempt or 0) >= int(max_attempts or 1):
            return False
        return status_code in (None, "", 0)
