# DO NOT EDIT THIS FILE!
#
# This code is generated off of PyCDP modules. If you need to make
# changes, edit the generator and regenerate all of the modules.

from __future__ import annotations
import typing

from ..context import get_connection_context, get_session_context

import cdp.indexed_db
from cdp.indexed_db import (
    DataEntry,
    DatabaseWithObjectStores,
    Key,
    KeyPath,
    KeyRange,
    ObjectStore,
    ObjectStoreIndex
)


async def clear_object_store(
        security_origin: str,
        database_name: str,
        object_store_name: str
    ) -> None:
    '''
    Clears all entries from an object store.

    :param security_origin: Security origin.
    :param database_name: Database name.
    :param object_store_name: Object store name.
    '''
    session = get_session_context('indexed_db.clear_object_store')
    return await session.execute(cdp.indexed_db.clear_object_store(security_origin, database_name, object_store_name))


async def delete_database(
        security_origin: str,
        database_name: str
    ) -> None:
    '''
    Deletes a database.

    :param security_origin: Security origin.
    :param database_name: Database name.
    '''
    session = get_session_context('indexed_db.delete_database')
    return await session.execute(cdp.indexed_db.delete_database(security_origin, database_name))


async def delete_object_store_entries(
        security_origin: str,
        database_name: str,
        object_store_name: str,
        key_range: KeyRange
    ) -> None:
    '''
    Delete a range of entries from an object store

    :param security_origin:
    :param database_name:
    :param object_store_name:
    :param key_range: Range of entry keys to delete
    '''
    session = get_session_context('indexed_db.delete_object_store_entries')
    return await session.execute(cdp.indexed_db.delete_object_store_entries(security_origin, database_name, object_store_name, key_range))


async def disable() -> None:
    '''
    Disables events from backend.
    '''
    session = get_session_context('indexed_db.disable')
    return await session.execute(cdp.indexed_db.disable())


async def enable() -> None:
    '''
    Enables events from backend.
    '''
    session = get_session_context('indexed_db.enable')
    return await session.execute(cdp.indexed_db.enable())


async def get_metadata(
        security_origin: str,
        database_name: str,
        object_store_name: str
    ) -> typing.Tuple[float, float]:
    '''
    Gets metadata of an object store

    :param security_origin: Security origin.
    :param database_name: Database name.
    :param object_store_name: Object store name.
    :returns: A tuple with the following items:

        0. **entriesCount** – the entries count
        1. **keyGeneratorValue** – the current value of key generator, to become the next inserted key into the object store. Valid if objectStore.autoIncrement is true.
    '''
    session = get_session_context('indexed_db.get_metadata')
    return await session.execute(cdp.indexed_db.get_metadata(security_origin, database_name, object_store_name))


async def request_data(
        security_origin: str,
        database_name: str,
        object_store_name: str,
        index_name: str,
        skip_count: int,
        page_size: int,
        key_range: typing.Optional[KeyRange] = None
    ) -> typing.Tuple[typing.List[DataEntry], bool]:
    '''
    Requests data from object store or index.

    :param security_origin: Security origin.
    :param database_name: Database name.
    :param object_store_name: Object store name.
    :param index_name: Index name, empty string for object store data requests.
    :param skip_count: Number of records to skip.
    :param page_size: Number of records to fetch.
    :param key_range: *(Optional)* Key range.
    :returns: A tuple with the following items:

        0. **objectStoreDataEntries** – Array of object store data entries.
        1. **hasMore** – If true, there are more entries to fetch in the given range.
    '''
    session = get_session_context('indexed_db.request_data')
    return await session.execute(cdp.indexed_db.request_data(security_origin, database_name, object_store_name, index_name, skip_count, page_size, key_range))


async def request_database(
        security_origin: str,
        database_name: str
    ) -> DatabaseWithObjectStores:
    '''
    Requests database with given name in given frame.

    :param security_origin: Security origin.
    :param database_name: Database name.
    :returns: Database with an array of object stores.
    '''
    session = get_session_context('indexed_db.request_database')
    return await session.execute(cdp.indexed_db.request_database(security_origin, database_name))


async def request_database_names(
        security_origin: str
    ) -> typing.List[str]:
    '''
    Requests database names for given security origin.

    :param security_origin: Security origin.
    :returns: Database names for origin.
    '''
    session = get_session_context('indexed_db.request_database_names')
    return await session.execute(cdp.indexed_db.request_database_names(security_origin))
