from typing import Any
from typing import Optional


class Timeout(object):
    def __init__(
        self,                   # type: Timeout
        minutes=None,           # type: Optional[int]
        seconds=None,           # type: Optional[int]
        milliseconds=None,      # type: Optional[int]
        microseconds=None,      # type: Optional[int]
    ):
        # type: (...) -> None

        if minutes is None and seconds is None and milliseconds is None and microseconds is None:
            raise RuntimeError("At least one time field must be supplied")

        self.minutes = minutes if minutes is not None else 0
        self.seconds = seconds if seconds is not None else 0
        self.milliseconds = milliseconds if milliseconds is not None else 0
        self.microseconds = microseconds if microseconds is not None else 0

    def __eq__(
        self,       # type: Timeout
        other,      # type: Any
    ):
        # type: (...) -> bool

        if not isinstance(other, Timeout):
            return False

        return (
            self.minutes == other.minutes and
            self.seconds == other.seconds and
            self.milliseconds == other.milliseconds and
            self.microseconds == other.microseconds
        )

    def __ne__(
        self,       # type: Timeout
        other,      # type: Any
    ):
        # type: (...) -> bool

        return not self.__eq__(other)

    def __str__(
        self,       # type: Timeout
    ):
        # type: (...) -> str

        return str({
            "minutes": self.minutes,
            "seconds": self.seconds,
            "milliseconds": self.milliseconds,
            "microseconds": self.microseconds
        })
