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

import google.protobuf.message
import temporalio.api.common.v1
import temporalio.exceptions
import temporalio.runtime
from abc import ABC, abstractmethod
from dataclasses import dataclass
from datetime import timedelta
from enum import IntEnum
from typing import ClassVar, Generic, Mapping, Optional, Type, TypeVar, Union

"""Underlying gRPC services."""
__version__ = ...
ServiceRequest = TypeVar("ServiceRequest", bound=google.protobuf.message.Message)
ServiceResponse = TypeVar("ServiceResponse", bound=google.protobuf.message.Message)
logger = ...
LOG_PROTOS = ...
@dataclass
class TLSConfig:
    """TLS configuration for connecting to Temporal server."""
    server_root_ca_cert: Optional[bytes] = ...
    domain: Optional[str] = ...
    client_cert: Optional[bytes] = ...
    client_private_key: Optional[bytes] = ...


@dataclass
class RetryConfig:
    """Retry configuration for server calls."""
    initial_interval_millis: int = ...
    randomization_factor: float = ...
    multiplier: float = ...
    max_interval_millis: int = ...
    max_elapsed_time_millis: Optional[int] = ...
    max_retries: int = ...


@dataclass(frozen=True)
class KeepAliveConfig:
    """Keep-alive configuration for client connections."""
    interval_millis: int = ...
    timeout_millis: int = ...
    default: ClassVar[KeepAliveConfig]


@dataclass
class ConnectConfig:
    """Config for connecting to the server."""
    target_host: str
    tls: Union[bool, TLSConfig] = ...
    retry_config: Optional[RetryConfig] = ...
    keep_alive_config: Optional[KeepAliveConfig] = ...
    rpc_metadata: Mapping[str, str] = ...
    identity: str = ...
    lazy: bool = ...
    runtime: Optional[temporalio.runtime.Runtime] = ...
    def __post_init__(self) -> None:
        """Set extra defaults on unset properties."""
        ...
    


class ServiceClient(ABC):
    """Direct client to Temporal services."""
    @staticmethod
    async def connect(config: ConnectConfig) -> ServiceClient:
        """Connect directly to Temporal services."""
        ...
    
    def __init__(self, config: ConnectConfig) -> None:
        """Initialize the base service client."""
        ...
    
    async def check_health(self, *, service: str = ..., retry: bool = ..., metadata: Mapping[str, str] = ..., timeout: Optional[timedelta] = ...) -> bool:
        """Check whether the WorkflowService is up.

        In addition to accepting which service to check health on, this accepts
        some of the same parameters as other RPC calls. See
        :py:meth:`ServiceCall.__call__`.

        Returns:
            True when available, false if the server is running but the service
            is unavailable (rare), or raises an error if server/service cannot
            be reached.
        """
        ...
    
    @property
    @abstractmethod
    def worker_service_client(self) -> _BridgeServiceClient:
        """Underlying service client."""
        ...
    
    @abstractmethod
    def update_rpc_metadata(self, metadata: Mapping[str, str]) -> None:
        """Update service client's RPC metadata."""
        ...
    


class WorkflowService:
    """Client to the Temporal server's workflow service."""
    def __init__(self, client: ServiceClient) -> None:
        """Initialize the workflow service."""
        ...
    


class OperatorService:
    """Client to the Temporal server's operator service."""
    def __init__(self, client: ServiceClient) -> None:
        """Initialize the operator service."""
        ...
    


class TestService:
    """Client to the Temporal test server's test service."""
    def __init__(self, client: ServiceClient) -> None:
        """Initialize the test service."""
        ...
    


class ServiceCall(Generic[ServiceRequest, ServiceResponse]):
    """Callable RPC method for services."""
    def __init__(self, service_client: ServiceClient, name: str, req_type: Type[ServiceRequest], resp_type: Type[ServiceResponse], service: str) -> None:
        """Initialize the service call."""
        ...
    
    async def __call__(self, req: ServiceRequest, *, retry: bool = ..., metadata: Mapping[str, str] = ..., timeout: Optional[timedelta] = ...) -> ServiceResponse:
        """Invoke underlying client with the given request.

        Args:
            req: Request for the call.
            retry: If true, will use retry config to retry failed calls.
            metadata: Headers used on the RPC call. Keys here override
                client-level RPC metadata keys.
            timeout: Optional RPC deadline to set for the RPC call.

        Returns:
            RPC response.

        Raises:
            RPCError: Any RPC error that occurs during the call.
        """
        ...
    


class _BridgeServiceClient(ServiceClient):
    @staticmethod
    async def connect(config: ConnectConfig) -> _BridgeServiceClient:
        ...
    
    def __init__(self, config: ConnectConfig) -> None:
        ...
    
    @property
    def worker_service_client(self) -> _BridgeServiceClient:
        """Underlying service client."""
        ...
    
    def update_rpc_metadata(self, metadata: Mapping[str, str]) -> None:
        """Update Core client metadata."""
        ...
    


class RPCStatusCode(IntEnum):
    """Status code for :py:class:`RPCError`."""
    OK = ...
    CANCELLED = ...
    UNKNOWN = ...
    INVALID_ARGUMENT = ...
    DEADLINE_EXCEEDED = ...
    NOT_FOUND = ...
    ALREADY_EXISTS = ...
    PERMISSION_DENIED = ...
    RESOURCE_EXHAUSTED = ...
    FAILED_PRECONDITION = ...
    ABORTED = ...
    OUT_OF_RANGE = ...
    UNIMPLEMENTED = ...
    INTERNAL = ...
    UNAVAILABLE = ...
    DATA_LOSS = ...
    UNAUTHENTICATED = ...


class RPCError(temporalio.exceptions.TemporalError):
    """Error during RPC call."""
    def __init__(self, message: str, status: RPCStatusCode, raw_grpc_status: bytes) -> None:
        """Initialize RPC error."""
        ...
    
    @property
    def message(self) -> str:
        """Message for the error."""
        ...
    
    @property
    def status(self) -> RPCStatusCode:
        """Status code for the error."""
        ...
    
    @property
    def raw_grpc_status(self) -> bytes:
        """Raw gRPC status bytes."""
        ...
    
    @property
    def grpc_status(self) -> temporalio.api.common.v1.GrpcStatus:
        """Status of the gRPC call with details."""
        ...
    


