# This file was auto-generated by Fern from our API Definition.

import typing

from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.request_options import RequestOptions
from ..types.include_total_count import IncludeTotalCount
from ..types.request_after_opaque_cursor import RequestAfterOpaqueCursor
from ..types.request_page_size import RequestPageSize
from ..types.search_response import SearchResponse
from ..types.uuid_ import Uuid
from .raw_client import AsyncRawSearchClient, RawSearchClient
from .types.search_params_engine import SearchParamsEngine
from .types.search_params_filters import SearchParamsFilters

# this is used as the default value for optional parameters
OMIT = typing.cast(typing.Any, ...)


class SearchClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawSearchClient(client_wrapper=client_wrapper)

    @property
    def with_raw_response(self) -> RawSearchClient:
        """
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        RawSearchClient
        """
        return self._raw_client

    def search(
        self,
        account_id: Uuid,
        *,
        engine: SearchParamsEngine,
        query: str,
        after: typing.Optional[RequestAfterOpaqueCursor] = None,
        page_size: typing.Optional[RequestPageSize] = None,
        include_total_count: typing.Optional[IncludeTotalCount] = None,
        filters: typing.Optional[SearchParamsFilters] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> SearchResponse:
        """
        Search across assets, folders, and projects within an account.
        Rate Limits: 100 calls per 1.00 minute(s) per account_user

        Parameters
        ----------
        account_id : Uuid


        engine : SearchParamsEngine
            Search engine to use. Available engines: lexical, nlp.

        query : str
            The search query text

        after : typing.Optional[RequestAfterOpaqueCursor]
            Opaque Cursor query param for requests returning paginated results.
            <br/>
            NOTE: this value is auto-generated and included as part of links from a previous response. It is not intended to be human readable.

        page_size : typing.Optional[RequestPageSize]


        include_total_count : typing.Optional[IncludeTotalCount]


        filters : typing.Optional[SearchParamsFilters]
            Filters to control which types of results are returned

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        SearchResponse
            OK

        Examples
        --------
        from frameio_experimental import FrameioExperimental
        from frameio_experimental.search import SearchParamsFilters

        client = FrameioExperimental(
            api_version="YOUR_API_VERSION",
            token="YOUR_TOKEN",
        )
        client.search.search(
            account_id="b2702c44-c6da-4bb6-8bbd-be6e547ccf1b",
            after="<opaque_cursor>",
            page_size=10,
            include_total_count=False,
            engine="nlp",
            filters=SearchParamsFilters(
                files_and_version_stacks=True,
                folders=False,
                projects=False,
            ),
            query="red car driving on highway",
        )
        """
        _response = self._raw_client.search(
            account_id,
            engine=engine,
            query=query,
            after=after,
            page_size=page_size,
            include_total_count=include_total_count,
            filters=filters,
            request_options=request_options,
        )
        return _response.data


class AsyncSearchClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawSearchClient(client_wrapper=client_wrapper)

    @property
    def with_raw_response(self) -> AsyncRawSearchClient:
        """
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        AsyncRawSearchClient
        """
        return self._raw_client

    async def search(
        self,
        account_id: Uuid,
        *,
        engine: SearchParamsEngine,
        query: str,
        after: typing.Optional[RequestAfterOpaqueCursor] = None,
        page_size: typing.Optional[RequestPageSize] = None,
        include_total_count: typing.Optional[IncludeTotalCount] = None,
        filters: typing.Optional[SearchParamsFilters] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> SearchResponse:
        """
        Search across assets, folders, and projects within an account.
        Rate Limits: 100 calls per 1.00 minute(s) per account_user

        Parameters
        ----------
        account_id : Uuid


        engine : SearchParamsEngine
            Search engine to use. Available engines: lexical, nlp.

        query : str
            The search query text

        after : typing.Optional[RequestAfterOpaqueCursor]
            Opaque Cursor query param for requests returning paginated results.
            <br/>
            NOTE: this value is auto-generated and included as part of links from a previous response. It is not intended to be human readable.

        page_size : typing.Optional[RequestPageSize]


        include_total_count : typing.Optional[IncludeTotalCount]


        filters : typing.Optional[SearchParamsFilters]
            Filters to control which types of results are returned

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        SearchResponse
            OK

        Examples
        --------
        import asyncio

        from frameio_experimental import AsyncFrameioExperimental
        from frameio_experimental.search import SearchParamsFilters

        client = AsyncFrameioExperimental(
            api_version="YOUR_API_VERSION",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.search.search(
                account_id="b2702c44-c6da-4bb6-8bbd-be6e547ccf1b",
                after="<opaque_cursor>",
                page_size=10,
                include_total_count=False,
                engine="nlp",
                filters=SearchParamsFilters(
                    files_and_version_stacks=True,
                    folders=False,
                    projects=False,
                ),
                query="red car driving on highway",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.search(
            account_id,
            engine=engine,
            query=query,
            after=after,
            page_size=page_size,
            include_total_count=include_total_count,
            filters=filters,
            request_options=request_options,
        )
        return _response.data
