from typing import TYPE_CHECKING, Any, Type, Union

if TYPE_CHECKING:  # pragma: no cover
    from meiga.result import TF, TS, Result


def assert_failure(
    result: "Result[TS, TF]",
    value_is_instance_of: Union[Type[Any], None] = None,
    value_is_equal_to: Union[Any, None] = None,
) -> None:
    assert result.is_failure, f"result is not failure as expected. Given failure value is {result.value}"
    if value_is_instance_of:
        base = type(result.value)
        if isinstance(base, type) and base is type:
            base = result.value.__bases__

        assert isinstance(result.value, value_is_instance_of), (
            f"Value is not instance of {value_is_instance_of}. " f"Given value is {result.value} of {base}"
        )
    if value_is_equal_to:
        assert result.value == value_is_equal_to, (
            f"Value is not equal to {value_is_equal_to}. " f"Given value is {result.value}"
        )
