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

from dataclasses import dataclass
from typing import List, Optional, TYPE_CHECKING
from nats.js import JetStreamContext, api

if TYPE_CHECKING:
    ...
KV_OP = ...
KV_DEL = ...
KV_PURGE = ...
MSG_ROLLUP_SUBJECT = ...
class KeyValue:
    """
    KeyValue uses the JetStream KeyValue functionality.

    .. note::
       This functionality is EXPERIMENTAL and may be changed in later releases.

    ::

        import asyncio
        import nats

        async def main():
            nc = await nats.connect()
            js = nc.jetstream()

            # Create a KV
            kv = await js.create_key_value(bucket='MY_KV')

            # Set and retrieve a value
            await kv.put('hello', b'world')
            entry = await kv.get('hello')
            print(f'KeyValue.Entry: key={entry.key}, value={entry.value}')
            # KeyValue.Entry: key=hello, value=world

            await nc.close()

        if __name__ == '__main__':
            asyncio.run(main())

    """
    @dataclass
    class Entry:
        """
        An entry from a KeyValue store in JetStream.
        """
        bucket: str
        key: str
        value: Optional[bytes]
        revision: Optional[int]
        delta: Optional[int]
        created: Optional[int]
        operation: Optional[str]
        ...
    
    
    @dataclass(frozen=True)
    class BucketStatus:
        """
        BucketStatus is the status of a KeyValue bucket.
        """
        stream_info: api.StreamInfo
        bucket: str
        @property
        def values(self) -> int:
            """
            values returns the number of stored messages in the stream.
            """
            ...
        
        @property
        def history(self) -> int:
            """
            history returns the max msgs per subject.
            """
            ...
        
        @property
        def ttl(self) -> Optional[float]:
            """
            ttl returns the max age in seconds.
            """
            ...
        
    
    
    def __init__(self, name: str, stream: str, pre: str, js: JetStreamContext, direct: bool) -> None:
        ...
    
    async def get(self, key: str, revision: Optional[int] = ...) -> Entry:
        """
        get returns the latest value for the key.
        """
        ...
    
    async def put(self, key: str, value: bytes) -> int:
        """
        put will place the new value for the key into the store
        and return the revision number.
        """
        ...
    
    async def create(self, key: str, value: bytes) -> int:
        """
        create will add the key/value pair iff it does not exist.
        """
        ...
    
    async def update(self, key: str, value: bytes, last: Optional[int] = ...) -> int:
        """
        update will update the value iff the latest revision matches.
        """
        ...
    
    async def delete(self, key: str, last: Optional[int] = ...) -> bool:
        """
        delete will place a delete marker and remove all previous revisions.
        """
        ...
    
    async def purge(self, key: str) -> bool:
        """
        purge will remove the key and all revisions.
        """
        ...
    
    async def purge_deletes(self, olderthan: int = ...) -> bool:
        """
        purge will remove all current delete markers older.
        :param olderthan: time in seconds
        """
        ...
    
    async def status(self) -> BucketStatus:
        """
        status retrieves the status and configuration of a bucket.
        """
        ...
    
    class KeyWatcher:
        def __init__(self, js) -> None:
            ...
        
        async def stop(self): # -> None:
            """
            stop will stop this watcher.
            """
            ...
        
        async def updates(self, timeout=...): # -> Entry | None:
            """
            updates fetches the next update from a watcher.
            """
            ...
        
        def __aiter__(self): # -> Self:
            ...
        
        async def __anext__(self): # -> Entry:
            ...
        
    
    
    async def watchall(self, **kwargs) -> KeyWatcher:
        """
        watchall returns a KeyValue watcher that matches all the keys.
        """
        ...
    
    async def keys(self, **kwargs) -> List[str]:
        """
        keys will return a list of the keys from a KeyValue store.
        """
        ...
    
    async def history(self, key: str) -> List[Entry]:
        """
        history retrieves a list of the entries so far.
        """
        ...
    
    async def watch(self, keys, headers_only=..., include_history=..., ignore_deletes=..., meta_only=..., inactive_threshold=...) -> KeyWatcher:
        """
        watch will fire a callback when a key that matches the keys
        pattern is updated.
        The first update after starting the watch is None in case
        there are no pending updates.
        """
        ...
    


