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

import asyncio
from typing import AsyncIterator, Awaitable, Callable, Optional, TYPE_CHECKING
from nats.aio.msg import Msg

if TYPE_CHECKING:
    ...
DEFAULT_SUB_PENDING_MSGS_LIMIT = ...
DEFAULT_SUB_PENDING_BYTES_LIMIT = ...
class Subscription:
    """
    A Subscription represents interest in a particular subject.

    A Subscription should not be constructed directly, rather
    `connection.subscribe()` should be used to get a subscription.

    ::

        nc = await nats.connect()

        # Async Subscription
        async def cb(msg):
          print('Received', msg)
        await nc.subscribe('foo', cb=cb)

        # Sync Subscription
        sub = nc.subscribe('foo')
        msg = await sub.next_msg()
        print('Received', msg)

    """
    def __init__(self, conn, id: int = ..., subject: str = ..., queue: str = ..., cb: Optional[Callable[[Msg], Awaitable[None]]] = ..., future: Optional[asyncio.Future] = ..., max_msgs: int = ..., pending_msgs_limit: int = ..., pending_bytes_limit: int = ...) -> None:
        ...
    
    @property
    def subject(self) -> str:
        """
        Returns the subject of the `Subscription`.
        """
        ...
    
    @property
    def queue(self) -> str:
        """
        Returns the queue name of the `Subscription` if part of a queue group.
        """
        ...
    
    @property
    def messages(self) -> AsyncIterator[Msg]:
        """
        Retrieves an async iterator for the messages from the subscription.

        This is only available if a callback isn't provided when creating a
        subscription.

        ::
    
            nc = await nats.connect()
            sub = await nc.subscribe('foo')
            # Use `async for` which implicitly awaits messages
            async for msg in sub.messages:
                print('Received', msg)
        """
        ...
    
    @property
    def pending_msgs(self) -> int:
        """
        Number of delivered messages by the NATS Server that are being buffered
        in the pending queue.
        """
        ...
    
    @property
    def pending_bytes(self) -> int:
        """
        Size of data sent by the NATS Server that is being buffered
        in the pending queue.
        """
        ...
    
    @property
    def delivered(self) -> int:
        """
        Number of delivered messages to this subscription so far.
        """
        ...
    
    async def next_msg(self, timeout: Optional[float] = ...) -> Msg:
        """
        :params timeout: Time in seconds to wait for next message before timing out.
        :raises nats.errors.TimeoutError:

        next_msg can be used to retrieve the next message from a stream of messages using
        await syntax, this only works when not passing a callback on `subscribe`::

            sub = await nc.subscribe('hello')
            msg = await sub.next_msg(timeout=1)

        """
        ...
    
    async def drain(self): # -> None:
        """
        Removes interest in a subject, but will process remaining messages.
        """
        ...
    
    async def unsubscribe(self, limit: int = ...): # -> None:
        """
        :param limit: Max number of messages to receive before unsubscribing.

        Removes interest in a subject, remaining messages will be discarded.

        If `limit` is greater than zero, interest is not immediately removed,
        rather, interest will be automatically removed after `limit` messages
        are received.
        """
        ...
    


class _SubscriptionMessageIterator:
    def __init__(self, sub: Subscription) -> None:
        ...
    
    def __aiter__(self) -> _SubscriptionMessageIterator:
        ...
    
    async def __anext__(self) -> Msg:
        ...
    


