from __future__ import annotations


class ReconnectPolicy:
    def __init__(self, *, initial_sec: int = 2, max_sec: int = 60, multiplier: float = 2.0) -> None:
        if initial_sec < 1:
            raise ValueError("initial_sec must be >= 1")
        if max_sec < initial_sec:
            raise ValueError("max_sec must be >= initial_sec")
        if multiplier < 1:
            raise ValueError("multiplier must be >= 1")
        self.initial_sec = initial_sec
        self.max_sec = max_sec
        self.multiplier = multiplier

    def next_delay(self, failure_count: int) -> int:
        if failure_count <= 0:
            return self.initial_sec
        value = int(self.initial_sec * (self.multiplier ** (failure_count - 1)))
        return min(self.max_sec, max(self.initial_sec, value))
