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

import logging
import temporalio.common
import temporalio.client
from collections.abc import Awaitable, Mapping, MutableMapping, Sequence
from contextvars import ContextVar
from dataclasses import dataclass
from datetime import timedelta
from typing import Any, Callable, Optional, TYPE_CHECKING, Union, overload
from nexusrpc.handler import CancelOperationContext, StartOperationContext
from typing_extensions import Concatenate
from temporalio.nexus._token import WorkflowHandle
from temporalio.types import MethodAsyncNoParam, MethodAsyncSingleParam, MultiParamSpec, ParamType, ReturnType, SelfType

if TYPE_CHECKING:
    ...
_temporal_start_operation_context: ContextVar[_TemporalStartOperationContext] = ...
_temporal_cancel_operation_context: ContextVar[_TemporalCancelOperationContext] = ...
@dataclass(frozen=True)
class Info:
    """Information about the running Nexus operation.

    .. warning::
        This API is experimental and unstable.

    Retrieved inside a Nexus operation handler via :py:func:`info`.
    """
    task_queue: str
    ...


def in_operation() -> bool:
    """Whether the current code is inside a Nexus operation."""
    ...

def info() -> Info:
    """Get the current Nexus operation information."""
    ...

def client() -> temporalio.client.Client:
    """Get the Temporal client used by the worker handling the current Nexus operation."""
    ...

@dataclass
class _TemporalStartOperationContext:
    """Context for a Nexus start operation being handled by a Temporal Nexus Worker."""
    nexus_context: StartOperationContext
    info: Callable[[], Info]
    client: temporalio.client.Client
    @classmethod
    def get(cls) -> _TemporalStartOperationContext:
        ...
    
    def set(self) -> None:
        ...
    


class WorkflowRunOperationContext(StartOperationContext):
    """Context received by a workflow run operation.

    .. warning::
        This API is experimental and unstable.
    """
    def __init__(self, *args: Any, **kwargs: Any) -> None:
        """Initialize the workflow run operation context."""
        ...
    
    @overload
    async def start_workflow(self, workflow: MethodAsyncNoParam[SelfType, ReturnType], *, id: str, task_queue: Optional[str] = ..., execution_timeout: Optional[timedelta] = ..., run_timeout: Optional[timedelta] = ..., task_timeout: Optional[timedelta] = ..., id_reuse_policy: temporalio.common.WorkflowIDReusePolicy = ..., id_conflict_policy: temporalio.common.WorkflowIDConflictPolicy = ..., retry_policy: Optional[temporalio.common.RetryPolicy] = ..., cron_schedule: str = ..., memo: Optional[Mapping[str, Any]] = ..., search_attributes: Optional[Union[temporalio.common.TypedSearchAttributes, temporalio.common.SearchAttributes,]] = ..., static_summary: Optional[str] = ..., static_details: Optional[str] = ..., start_delay: Optional[timedelta] = ..., start_signal: Optional[str] = ..., start_signal_args: Sequence[Any] = ..., rpc_metadata: Mapping[str, str] = ..., rpc_timeout: Optional[timedelta] = ..., request_eager_start: bool = ..., priority: temporalio.common.Priority = ..., versioning_override: Optional[temporalio.common.VersioningOverride] = ...) -> WorkflowHandle[ReturnType]:
        ...
    
    @overload
    async def start_workflow(self, workflow: MethodAsyncSingleParam[SelfType, ParamType, ReturnType], arg: ParamType, *, id: str, task_queue: Optional[str] = ..., execution_timeout: Optional[timedelta] = ..., run_timeout: Optional[timedelta] = ..., task_timeout: Optional[timedelta] = ..., id_reuse_policy: temporalio.common.WorkflowIDReusePolicy = ..., id_conflict_policy: temporalio.common.WorkflowIDConflictPolicy = ..., retry_policy: Optional[temporalio.common.RetryPolicy] = ..., cron_schedule: str = ..., memo: Optional[Mapping[str, Any]] = ..., search_attributes: Optional[Union[temporalio.common.TypedSearchAttributes, temporalio.common.SearchAttributes,]] = ..., static_summary: Optional[str] = ..., static_details: Optional[str] = ..., start_delay: Optional[timedelta] = ..., start_signal: Optional[str] = ..., start_signal_args: Sequence[Any] = ..., rpc_metadata: Mapping[str, str] = ..., rpc_timeout: Optional[timedelta] = ..., request_eager_start: bool = ..., priority: temporalio.common.Priority = ..., versioning_override: Optional[temporalio.common.VersioningOverride] = ...) -> WorkflowHandle[ReturnType]:
        ...
    
    @overload
    async def start_workflow(self, workflow: Callable[Concatenate[SelfType, MultiParamSpec], Awaitable[ReturnType]], *, args: Sequence[Any], id: str, task_queue: Optional[str] = ..., execution_timeout: Optional[timedelta] = ..., run_timeout: Optional[timedelta] = ..., task_timeout: Optional[timedelta] = ..., id_reuse_policy: temporalio.common.WorkflowIDReusePolicy = ..., id_conflict_policy: temporalio.common.WorkflowIDConflictPolicy = ..., retry_policy: Optional[temporalio.common.RetryPolicy] = ..., cron_schedule: str = ..., memo: Optional[Mapping[str, Any]] = ..., search_attributes: Optional[Union[temporalio.common.TypedSearchAttributes, temporalio.common.SearchAttributes,]] = ..., static_summary: Optional[str] = ..., static_details: Optional[str] = ..., start_delay: Optional[timedelta] = ..., start_signal: Optional[str] = ..., start_signal_args: Sequence[Any] = ..., rpc_metadata: Mapping[str, str] = ..., rpc_timeout: Optional[timedelta] = ..., request_eager_start: bool = ..., priority: temporalio.common.Priority = ..., versioning_override: Optional[temporalio.common.VersioningOverride] = ...) -> WorkflowHandle[ReturnType]:
        ...
    
    @overload
    async def start_workflow(self, workflow: str, arg: Any = ..., *, args: Sequence[Any] = ..., id: str, task_queue: Optional[str] = ..., result_type: Optional[type[ReturnType]] = ..., execution_timeout: Optional[timedelta] = ..., run_timeout: Optional[timedelta] = ..., task_timeout: Optional[timedelta] = ..., id_reuse_policy: temporalio.common.WorkflowIDReusePolicy = ..., id_conflict_policy: temporalio.common.WorkflowIDConflictPolicy = ..., retry_policy: Optional[temporalio.common.RetryPolicy] = ..., cron_schedule: str = ..., memo: Optional[Mapping[str, Any]] = ..., search_attributes: Optional[Union[temporalio.common.TypedSearchAttributes, temporalio.common.SearchAttributes,]] = ..., static_summary: Optional[str] = ..., static_details: Optional[str] = ..., start_delay: Optional[timedelta] = ..., start_signal: Optional[str] = ..., start_signal_args: Sequence[Any] = ..., rpc_metadata: Mapping[str, str] = ..., rpc_timeout: Optional[timedelta] = ..., request_eager_start: bool = ..., priority: temporalio.common.Priority = ..., versioning_override: Optional[temporalio.common.VersioningOverride] = ...) -> WorkflowHandle[ReturnType]:
        ...
    
    async def start_workflow(self, workflow: Union[str, Callable[..., Awaitable[ReturnType]]], arg: Any = ..., *, args: Sequence[Any] = ..., id: str, task_queue: Optional[str] = ..., result_type: Optional[type] = ..., execution_timeout: Optional[timedelta] = ..., run_timeout: Optional[timedelta] = ..., task_timeout: Optional[timedelta] = ..., id_reuse_policy: temporalio.common.WorkflowIDReusePolicy = ..., id_conflict_policy: temporalio.common.WorkflowIDConflictPolicy = ..., retry_policy: Optional[temporalio.common.RetryPolicy] = ..., cron_schedule: str = ..., memo: Optional[Mapping[str, Any]] = ..., search_attributes: Optional[Union[temporalio.common.TypedSearchAttributes, temporalio.common.SearchAttributes,]] = ..., static_summary: Optional[str] = ..., static_details: Optional[str] = ..., start_delay: Optional[timedelta] = ..., start_signal: Optional[str] = ..., start_signal_args: Sequence[Any] = ..., rpc_metadata: Mapping[str, str] = ..., rpc_timeout: Optional[timedelta] = ..., request_eager_start: bool = ..., priority: temporalio.common.Priority = ..., versioning_override: Optional[temporalio.common.VersioningOverride] = ...) -> WorkflowHandle[ReturnType]:
        """Start a workflow that will deliver the result of the Nexus operation.

        The workflow will be started in the same namespace as the Nexus worker, using
        the same client as the worker. If task queue is not specified, the worker's task
        queue will be used.

        See :py:meth:`temporalio.client.Client.start_workflow` for all arguments.

        The return value is :py:class:`temporalio.nexus.WorkflowHandle`.

        The workflow will be started as usual, with the following modifications:

        - On workflow completion, Temporal server will deliver the workflow result to
            the Nexus operation caller, using the callback from the Nexus operation start
            request.

        - The request ID from the Nexus operation start request will be used as the
            request ID for the start workflow request.

        - Inbound links to the caller that were submitted in the Nexus start operation
            request will be attached to the started workflow and, outbound links to the
            started workflow will be added to the Nexus start operation response. If the
            Nexus caller is itself a workflow, this means that the workflow in the caller
            namespace web UI will contain links to the started workflow, and vice versa.
        """
        ...
    


@dataclass(frozen=True)
class NexusCallback:
    """Nexus callback to attach to events such as workflow completion.

    .. warning::
        This API is experimental and unstable.
    """
    url: str
    headers: Mapping[str, str]
    ...


@dataclass(frozen=True)
class _TemporalCancelOperationContext:
    """Context for a Nexus cancel operation being handled by a Temporal Nexus Worker."""
    nexus_context: CancelOperationContext
    info: Callable[[], Info]
    client: temporalio.client.Client
    @classmethod
    def get(cls) -> _TemporalCancelOperationContext:
        ...
    
    def set(self) -> None:
        ...
    


class LoggerAdapter(logging.LoggerAdapter):
    """Logger adapter that adds Nexus operation context information."""
    def __init__(self, logger: logging.Logger, extra: Optional[Mapping[str, Any]]) -> None:
        """Initialize the logger adapter."""
        ...
    
    def process(self, msg: Any, kwargs: MutableMapping[str, Any]) -> tuple[Any, MutableMapping[str, Any]]:
        """Process log records to add Nexus operation context."""
        ...
    


logger = ...
