"""
This type stub file was generated by pyright.
"""

import temporalio.api.failure.v1
from enum import IntEnum
from typing import Any, Optional, Sequence, Tuple

"""Common Temporal exceptions."""
class TemporalError(Exception):
    """Base for all Temporal exceptions."""
    @property
    def cause(self) -> Optional[BaseException]:
        """Cause of the exception.

        This is the same as ``Exception.__cause__``.
        """
        ...
    


class FailureError(TemporalError):
    """Base for runtime failures during workflow/activity execution."""
    def __init__(self, message: str, *, failure: Optional[temporalio.api.failure.v1.Failure] = ..., exc_args: Optional[Tuple] = ...) -> None:
        """Initialize a failure error."""
        ...
    
    @property
    def message(self) -> str:
        """Message."""
        ...
    
    @property
    def failure(self) -> Optional[temporalio.api.failure.v1.Failure]:
        """Underlying protobuf failure object."""
        ...
    


class WorkflowAlreadyStartedError(FailureError):
    """Thrown by a client or workflow when a workflow execution has already started.

    Attributes:
        workflow_id: ID of the already-started workflow.
        workflow_type: Workflow type name of the already-started workflow.
        run_id: Run ID of the already-started workflow if this was raised by the
            client.
    """
    def __init__(self, workflow_id: str, workflow_type: str, *, run_id: Optional[str] = ...) -> None:
        """Initialize a workflow already started error."""
        ...
    


class ApplicationError(FailureError):
    """Error raised during workflow/activity execution."""
    def __init__(self, message: str, *details: Any, type: Optional[str] = ..., non_retryable: bool = ...) -> None:
        """Initialize an application error."""
        ...
    
    @property
    def details(self) -> Sequence[Any]:
        """User-defined details on the error."""
        ...
    
    @property
    def type(self) -> Optional[str]:
        """General error type."""
        ...
    
    @property
    def non_retryable(self) -> bool:
        """Whether the error is non-retryable."""
        ...
    


class CancelledError(FailureError):
    """Error raised on workflow/activity cancellation."""
    def __init__(self, message: str = ..., *details: Any) -> None:
        """Initialize a cancelled error."""
        ...
    
    @property
    def details(self) -> Sequence[Any]:
        """User-defined details on the error."""
        ...
    


class TerminatedError(FailureError):
    """Error raised on workflow cancellation."""
    def __init__(self, message: str, *details: Any) -> None:
        """Initialize a terminated error."""
        ...
    
    @property
    def details(self) -> Sequence[Any]:
        """User-defined details on the error."""
        ...
    


class TimeoutType(IntEnum):
    """Type of timeout for :py:class:`TimeoutError`."""
    START_TO_CLOSE = ...
    SCHEDULE_TO_START = ...
    SCHEDULE_TO_CLOSE = ...
    HEARTBEAT = ...


class TimeoutError(FailureError):
    """Error raised on workflow/activity timeout."""
    def __init__(self, message: str, *, type: Optional[TimeoutType], last_heartbeat_details: Sequence[Any]) -> None:
        """Initialize a timeout error."""
        ...
    
    @property
    def type(self) -> Optional[TimeoutType]:
        """Type of timeout error."""
        ...
    
    @property
    def last_heartbeat_details(self) -> Sequence[Any]:
        """Last heartbeat details if this is for an activity heartbeat."""
        ...
    


class ServerError(FailureError):
    """Error originating in the Temporal server."""
    def __init__(self, message: str, *, non_retryable: bool = ...) -> None:
        """Initialize a server error."""
        ...
    
    @property
    def non_retryable(self) -> bool:
        """Whether this error is non-retryable."""
        ...
    


class RetryState(IntEnum):
    """Current retry state of the workflow/activity during error."""
    IN_PROGRESS = ...
    NON_RETRYABLE_FAILURE = ...
    TIMEOUT = ...
    MAXIMUM_ATTEMPTS_REACHED = ...
    RETRY_POLICY_NOT_SET = ...
    INTERNAL_SERVER_ERROR = ...
    CANCEL_REQUESTED = ...


class ActivityError(FailureError):
    """Error raised on activity failure."""
    def __init__(self, message: str, *, scheduled_event_id: int, started_event_id: int, identity: str, activity_type: str, activity_id: str, retry_state: Optional[RetryState]) -> None:
        """Initialize an activity error."""
        ...
    
    @property
    def scheduled_event_id(self) -> int:
        """Scheduled event ID for this error."""
        ...
    
    @property
    def started_event_id(self) -> int:
        """Started event ID for this error."""
        ...
    
    @property
    def identity(self) -> str:
        """Identity for this error."""
        ...
    
    @property
    def activity_type(self) -> str:
        """Activity type for this error."""
        ...
    
    @property
    def activity_id(self) -> str:
        """Activity ID for this error."""
        ...
    
    @property
    def retry_state(self) -> Optional[RetryState]:
        """Retry state for this error."""
        ...
    


class ChildWorkflowError(FailureError):
    """Error raised on child workflow failure."""
    def __init__(self, message: str, *, namespace: str, workflow_id: str, run_id: str, workflow_type: str, initiated_event_id: int, started_event_id: int, retry_state: Optional[RetryState]) -> None:
        """Initialize a child workflow error."""
        ...
    
    @property
    def namespace(self) -> str:
        """Namespace for this error."""
        ...
    
    @property
    def workflow_id(self) -> str:
        """Workflow ID for this error."""
        ...
    
    @property
    def run_id(self) -> str:
        """Run ID for this error."""
        ...
    
    @property
    def workflow_type(self) -> str:
        """Workflow type for this error."""
        ...
    
    @property
    def initiated_event_id(self) -> int:
        """Initiated event ID for this error."""
        ...
    
    @property
    def started_event_id(self) -> int:
        """Started event ID for this error."""
        ...
    
    @property
    def retry_state(self) -> Optional[RetryState]:
        """Retry state for this error."""
        ...
    


def is_cancelled_exception(exception: BaseException) -> bool:
    """Check whether the given exception is considered a cancellation exception
    according to Temporal.

    This is often used in a conditional of a catch clause to check whether a
    cancel occurred inside of a workflow. This can occur from
    :py:class:`asyncio.CancelledError` or :py:class:`CancelledError` or either
    :py:class:`ActivityError` or :py:class:`ChildWorkflowError` if either of
    those latter two have a :py:class:`CancelledError` cause.

    Args:
        exception: Exception to check.

    Returns:
        True if a cancelled exception, false if not.
    """
    ...

