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

import asyncio
import contextvars
import random
import temporalio.bridge.proto.activity_result
import temporalio.bridge.proto.workflow_activation
import temporalio.bridge.proto.workflow_completion
import temporalio.common
import temporalio.converter
import temporalio.workflow
from abc import ABC, abstractmethod
from dataclasses import dataclass
from datetime import timedelta
from typing import Any, Awaitable, Callable, Generator, Mapping, NoReturn, Optional, Sequence, Type, TypeVar, Union
from typing_extensions import TypeAlias, TypedDict
from ._interceptor import ContinueAsNewInput, ExecuteWorkflowInput, HandleQueryInput, HandleSignalInput, HandleUpdateInput, SignalChildWorkflowInput, SignalExternalWorkflowInput, StartActivityInput, StartChildWorkflowInput, StartLocalActivityInput, WorkflowInboundInterceptor, WorkflowOutboundInterceptor

"""
This type stub file was generated by pyright.
"""
logger = ...
class WorkflowRunner(ABC):
    """Abstract runner for workflows that creates workflow instances to run.

    :py:class:`UnsandboxedWorkflowRunner` is an implementation that locally runs
    the workflow.
    """
    @abstractmethod
    def prepare_workflow(self, defn: temporalio.workflow._Definition) -> None:
        """Prepare a workflow for future execution.

        This is run once for each workflow definition when a worker starts. This
        allows the runner to do anything necessarily to prepare for this
        definition to be used multiple times in create_instance.

        Args:
            defn: The workflow definition.
        """
        ...
    
    @abstractmethod
    def create_instance(self, det: WorkflowInstanceDetails) -> WorkflowInstance:
        """Create a workflow instance that can handle activations.

        Args:
            det: Details that can be used to create the instance.

        Returns:
            Workflow instance that can handle activations.
        """
        ...
    


@dataclass(frozen=True)
class WorkflowInstanceDetails:
    """Immutable details for creating a workflow instance."""
    payload_converter_class: Type[temporalio.converter.PayloadConverter]
    failure_converter_class: Type[temporalio.converter.FailureConverter]
    interceptor_classes: Sequence[Type[WorkflowInboundInterceptor]]
    defn: temporalio.workflow._Definition
    info: temporalio.workflow.Info
    randomness_seed: int
    extern_functions: Mapping[str, Callable]
    disable_eager_activity_execution: bool
    ...


class WorkflowInstance(ABC):
    """Instance of a workflow that can handle activations."""
    @abstractmethod
    def activate(self, act: temporalio.bridge.proto.workflow_activation.WorkflowActivation) -> temporalio.bridge.proto.workflow_completion.WorkflowActivationCompletion:
        """Handle an activation and return completion.

        This should never raise an exception, but instead catch all exceptions
        and set as completion failure.

        Args:
            act: Protobuf activation.

        Returns:
            Completion object with successful commands set or failure info set.
        """
        ...
    


class UnsandboxedWorkflowRunner(WorkflowRunner):
    """Workflow runner that does not do any sandboxing."""
    def prepare_workflow(self, defn: temporalio.workflow._Definition) -> None:
        """Implements :py:meth:`WorkflowRunner.prepare_workflow` as a no-op."""
        ...
    
    def create_instance(self, det: WorkflowInstanceDetails) -> WorkflowInstance:
        """Implements :py:meth:`WorkflowRunner.create_instance`."""
        ...
    


_T = TypeVar("_T")
_Context: TypeAlias = ...
_ExceptionHandler: TypeAlias = ...
class _WorkflowInstanceImpl(WorkflowInstance, temporalio.workflow._Runtime, asyncio.AbstractEventLoop):
    def __init__(self, det: WorkflowInstanceDetails) -> None:
        ...
    
    def __del__(self) -> None:
        ...
    
    def activate(self, act: temporalio.bridge.proto.workflow_activation.WorkflowActivation) -> temporalio.bridge.proto.workflow_completion.WorkflowActivationCompletion:
        ...
    
    def workflow_continue_as_new(self, *args: Any, workflow: Union[None, Callable, str], task_queue: Optional[str], run_timeout: Optional[timedelta], task_timeout: Optional[timedelta], retry_policy: Optional[temporalio.common.RetryPolicy], memo: Optional[Mapping[str, Any]], search_attributes: Optional[Union[temporalio.common.SearchAttributes, temporalio.common.TypedSearchAttributes,]], versioning_intent: Optional[temporalio.workflow.VersioningIntent]) -> NoReturn:
        ...
    
    def workflow_extern_functions(self) -> Mapping[str, Callable]:
        ...
    
    def workflow_get_current_history_length(self) -> int:
        ...
    
    def workflow_get_current_history_size(self) -> int:
        ...
    
    def workflow_get_external_workflow_handle(self, id: str, *, run_id: Optional[str]) -> temporalio.workflow.ExternalWorkflowHandle[Any]:
        ...
    
    def workflow_get_query_handler(self, name: Optional[str]) -> Optional[Callable]:
        ...
    
    def workflow_get_signal_handler(self, name: Optional[str]) -> Optional[Callable]:
        ...
    
    def workflow_get_update_handler(self, name: Optional[str]) -> Optional[Callable]:
        ...
    
    def workflow_get_update_validator(self, name: Optional[str]) -> Optional[Callable]:
        ...
    
    def workflow_info(self) -> temporalio.workflow.Info:
        ...
    
    def workflow_is_continue_as_new_suggested(self) -> bool:
        ...
    
    def workflow_is_replaying(self) -> bool:
        ...
    
    def workflow_memo(self) -> Mapping[str, Any]:
        ...
    
    def workflow_memo_value(self, key: str, default: Any, *, type_hint: Optional[Type]) -> Any:
        ...
    
    def workflow_metric_meter(self) -> temporalio.common.MetricMeter:
        ...
    
    def workflow_patch(self, id: str, *, deprecated: bool) -> bool:
        ...
    
    def workflow_payload_converter(self) -> temporalio.converter.PayloadConverter:
        ...
    
    def workflow_random(self) -> random.Random:
        ...
    
    def workflow_set_query_handler(self, name: Optional[str], handler: Optional[Callable]) -> None:
        ...
    
    def workflow_set_signal_handler(self, name: Optional[str], handler: Optional[Callable]) -> None:
        ...
    
    def workflow_set_update_handler(self, name: Optional[str], handler: Optional[Callable], validator: Optional[Callable]) -> None:
        ...
    
    def workflow_start_activity(self, activity: Any, *args: Any, task_queue: Optional[str], result_type: Optional[Type], schedule_to_close_timeout: Optional[timedelta], schedule_to_start_timeout: Optional[timedelta], start_to_close_timeout: Optional[timedelta], heartbeat_timeout: Optional[timedelta], retry_policy: Optional[temporalio.common.RetryPolicy], cancellation_type: temporalio.workflow.ActivityCancellationType, activity_id: Optional[str], versioning_intent: Optional[temporalio.workflow.VersioningIntent]) -> temporalio.workflow.ActivityHandle[Any]:
        ...
    
    async def workflow_start_child_workflow(self, workflow: Any, *args: Any, id: str, task_queue: Optional[str], result_type: Optional[Type], cancellation_type: temporalio.workflow.ChildWorkflowCancellationType, parent_close_policy: temporalio.workflow.ParentClosePolicy, execution_timeout: Optional[timedelta], run_timeout: Optional[timedelta], task_timeout: Optional[timedelta], id_reuse_policy: temporalio.common.WorkflowIDReusePolicy, retry_policy: Optional[temporalio.common.RetryPolicy], cron_schedule: str, memo: Optional[Mapping[str, Any]], search_attributes: Optional[Union[temporalio.common.SearchAttributes, temporalio.common.TypedSearchAttributes,]], versioning_intent: Optional[temporalio.workflow.VersioningIntent]) -> temporalio.workflow.ChildWorkflowHandle[Any, Any]:
        ...
    
    def workflow_start_local_activity(self, activity: Any, *args: Any, result_type: Optional[Type], schedule_to_close_timeout: Optional[timedelta], schedule_to_start_timeout: Optional[timedelta], start_to_close_timeout: Optional[timedelta], retry_policy: Optional[temporalio.common.RetryPolicy], local_retry_threshold: Optional[timedelta], cancellation_type: temporalio.workflow.ActivityCancellationType, activity_id: Optional[str]) -> temporalio.workflow.ActivityHandle[Any]:
        ...
    
    def workflow_time_ns(self) -> int:
        ...
    
    def workflow_upsert_search_attributes(self, attributes: Union[temporalio.common.SearchAttributes, Sequence[temporalio.common.SearchAttributeUpdate],]) -> None:
        ...
    
    async def workflow_wait_condition(self, fn: Callable[[], bool], *, timeout: Optional[float] = ...) -> None:
        ...
    
    def call_soon(self, callback: Callable[..., Any], *args: Any, context: Optional[contextvars.Context] = ...) -> asyncio.Handle:
        ...
    
    def call_later(self, delay: float, callback: Callable[..., Any], *args: Any, context: Optional[contextvars.Context] = ...) -> asyncio.TimerHandle:
        ...
    
    def time(self) -> float:
        ...
    
    def create_future(self) -> asyncio.Future[Any]:
        ...
    
    def create_task(self, coro: Union[Awaitable[_T], Generator[Any, None, _T]], *, name: Optional[str] = ..., context: Optional[contextvars.Context] = ...) -> asyncio.Task[_T]:
        ...
    
    def get_exception_handler(self) -> Optional[_ExceptionHandler]:
        ...
    
    def set_exception_handler(self, handler: Optional[_ExceptionHandler]) -> None:
        ...
    
    def default_exception_handler(self, context: _Context) -> None:
        ...
    
    def call_exception_handler(self, context: _Context) -> None:
        ...
    
    def get_debug(self) -> bool:
        ...
    


class _WorkflowInboundImpl(WorkflowInboundInterceptor):
    def __init__(self, instance: _WorkflowInstanceImpl) -> None:
        ...
    
    def init(self, outbound: WorkflowOutboundInterceptor) -> None:
        ...
    
    async def execute_workflow(self, input: ExecuteWorkflowInput) -> Any:
        ...
    
    async def handle_signal(self, input: HandleSignalInput) -> None:
        ...
    
    async def handle_query(self, input: HandleQueryInput) -> Any:
        ...
    
    def handle_update_validator(self, input: HandleUpdateInput) -> None:
        ...
    
    async def handle_update_handler(self, input: HandleUpdateInput) -> Any:
        ...
    


class _WorkflowOutboundImpl(WorkflowOutboundInterceptor):
    def __init__(self, instance: _WorkflowInstanceImpl) -> None:
        ...
    
    def continue_as_new(self, input: ContinueAsNewInput) -> NoReturn:
        ...
    
    def info(self) -> temporalio.workflow.Info:
        ...
    
    async def signal_child_workflow(self, input: SignalChildWorkflowInput) -> None:
        ...
    
    async def signal_external_workflow(self, input: SignalExternalWorkflowInput) -> None:
        ...
    
    def start_activity(self, input: StartActivityInput) -> temporalio.workflow.ActivityHandle:
        ...
    
    async def start_child_workflow(self, input: StartChildWorkflowInput) -> temporalio.workflow.ChildWorkflowHandle:
        ...
    
    def start_local_activity(self, input: StartLocalActivityInput) -> temporalio.workflow.ActivityHandle:
        ...
    


class _TimerHandle(asyncio.TimerHandle):
    def __init__(self, seq: int, when: float, callback: Callable[..., Any], args: Sequence[Any], loop: asyncio.AbstractEventLoop, context: Optional[contextvars.Context]) -> None:
        ...
    


class _ActivityDoBackoffError(BaseException):
    def __init__(self, backoff: temporalio.bridge.proto.activity_result.DoBackoff) -> None:
        ...
    


class _ActivityHandle(temporalio.workflow.ActivityHandle[Any]):
    def __init__(self, instance: _WorkflowInstanceImpl, input: Union[StartActivityInput, StartLocalActivityInput], fn: Awaitable[Any]) -> None:
        ...
    
    def cancel(self, msg: Optional[Any] = ...) -> bool:
        ...
    


class _ChildWorkflowHandle(temporalio.workflow.ChildWorkflowHandle[Any, Any]):
    def __init__(self, instance: _WorkflowInstanceImpl, seq: int, input: StartChildWorkflowInput, fn: Awaitable[Any]) -> None:
        ...
    
    @property
    def id(self) -> str:
        ...
    
    @property
    def first_execution_run_id(self) -> Optional[str]:
        ...
    
    async def signal(self, signal: Union[str, Callable], arg: Any = ..., *, args: Sequence[Any] = ...) -> None:
        ...
    


class _ExternalWorkflowHandle(temporalio.workflow.ExternalWorkflowHandle[Any]):
    def __init__(self, instance: _WorkflowInstanceImpl, id: str, run_id: Optional[str]) -> None:
        ...
    
    @property
    def id(self) -> str:
        ...
    
    @property
    def run_id(self) -> Optional[str]:
        ...
    
    async def signal(self, signal: Union[str, Callable], arg: Any = ..., *, args: Sequence[Any] = ...) -> None:
        ...
    
    async def cancel(self) -> None:
        ...
    


class _ContinueAsNewError(temporalio.workflow.ContinueAsNewError):
    def __init__(self, instance: _WorkflowInstanceImpl, input: ContinueAsNewInput) -> None:
        ...
    


class _WorkflowExternFunctions(TypedDict):
    __temporal_get_metric_meter: Callable[[], temporalio.common.MetricMeter]
    ...


class _ReplaySafeMetricMeter(temporalio.common.MetricMeter):
    def __init__(self, underlying: temporalio.common.MetricMeter) -> None:
        ...
    
    def create_counter(self, name: str, description: Optional[str] = ..., unit: Optional[str] = ...) -> temporalio.common.MetricCounter:
        ...
    
    def create_histogram(self, name: str, description: Optional[str] = ..., unit: Optional[str] = ...) -> temporalio.common.MetricHistogram:
        ...
    
    def create_gauge(self, name: str, description: Optional[str] = ..., unit: Optional[str] = ...) -> temporalio.common.MetricGauge:
        ...
    
    def with_additional_attributes(self, additional_attributes: temporalio.common.MetricAttributes) -> temporalio.common.MetricMeter:
        ...
    


class _ReplaySafeMetricCounter(temporalio.common.MetricCounter):
    def __init__(self, underlying: temporalio.common.MetricCounter) -> None:
        ...
    
    @property
    def name(self) -> str:
        ...
    
    @property
    def description(self) -> Optional[str]:
        ...
    
    @property
    def unit(self) -> Optional[str]:
        ...
    
    def add(self, value: int, additional_attributes: Optional[temporalio.common.MetricAttributes] = ...) -> None:
        ...
    
    def with_additional_attributes(self, additional_attributes: temporalio.common.MetricAttributes) -> temporalio.common.MetricCounter:
        ...
    


class _ReplaySafeMetricHistogram(temporalio.common.MetricHistogram):
    def __init__(self, underlying: temporalio.common.MetricHistogram) -> None:
        ...
    
    @property
    def name(self) -> str:
        ...
    
    @property
    def description(self) -> Optional[str]:
        ...
    
    @property
    def unit(self) -> Optional[str]:
        ...
    
    def record(self, value: int, additional_attributes: Optional[temporalio.common.MetricAttributes] = ...) -> None:
        ...
    
    def with_additional_attributes(self, additional_attributes: temporalio.common.MetricAttributes) -> temporalio.common.MetricHistogram:
        ...
    


class _ReplaySafeMetricGauge(temporalio.common.MetricGauge):
    def __init__(self, underlying: temporalio.common.MetricGauge) -> None:
        ...
    
    @property
    def name(self) -> str:
        ...
    
    @property
    def description(self) -> Optional[str]:
        ...
    
    @property
    def unit(self) -> Optional[str]:
        ...
    
    def set(self, value: int, additional_attributes: Optional[temporalio.common.MetricAttributes] = ...) -> None:
        ...
    
    def with_additional_attributes(self, additional_attributes: temporalio.common.MetricAttributes) -> temporalio.common.MetricGauge:
        ...
    


