from typing import (
    TypeVar,
    Type,
    Dict,
    Any,
)

from ._AwakableNoSleeper import AwakableNoSleeper
from ._ClockSpy import ClockSpy
from ._ClockStub import ClockStub
from ._ForeverSleeper import ForeverSleeper
from ._LoopedListDateIterator import LoopedListDateIterator
from ._NoSleeper import NoSleeper
from ._SimpleSpy import SimpleSpy
from ._SimpleStub import SimpleStub
from ._SingleDateIterator import SingleDateIterator
from ._SleeperSpy import SleeperSpy
from ._SpyCall import SpyCall
from ._TimeDeltaDateIterator import TimeDeltaDateIterator
from ._NoWaitCondition import NoWaitCondition

AnyType = TypeVar("AnyType")


def a_stub(
    interface,  # type: Type[AnyType]
    ret,        # type: Dict[Any, Any]
):
    # type: (...) -> AnyType
    return SimpleStub(interface, ret)


def a_spy(
    interface,         # type: Type[AnyType],
    deep_clone=False,  # type: bool
    ret=None,            # type: Dict[Any, Any]
):
    # type: (...) -> SimpleSpy
    if ret is None:
        ret = {}
    return SimpleSpy(interface, ret, deep_clone)


def return_or_raise(value):
    if isinstance(value, Exception):
        raise value

    return value
