# 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.create_crawl_job_response_model import CreateCrawlJobResponseModel
from ....types.get_crawl_job_response_model import GetCrawlJobResponseModel
from ....types.list_crawl_jobs_response_model import ListCrawlJobsResponseModel
from .raw_client import AsyncRawCrawlJobsClient, RawCrawlJobsClient

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


class CrawlJobsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawCrawlJobsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawCrawlJobsClient
        """
        return self._raw_client

    def list(
        self,
        *,
        include_job_ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        page_size: typing.Optional[int] = None,
        cursor: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ListCrawlJobsResponseModel:
        """
        Get a list of ongoing and recent crawl jobs for the user.

        Parameters
        ----------
        include_job_ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            Ids of additional crawl jobs to retrieve

        page_size : typing.Optional[int]
            How many documents to return at maximum. Can not exceed 100, defaults to 30.

        cursor : typing.Optional[str]
            Used for fetching next page. Cursor is returned in the response.

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

        Returns
        -------
        ListCrawlJobsResponseModel
            Successful Response

        Examples
        --------
        from elevenlabs import ElevenLabs

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.conversational_ai.knowledge_base.crawl_jobs.list(
            include_job_ids=["include_job_ids"],
            page_size=1,
            cursor="cursor",
        )
        """
        _response = self._raw_client.list(
            include_job_ids=include_job_ids, page_size=page_size, cursor=cursor, request_options=request_options
        )
        return _response.data

    def create(
        self,
        *,
        url: str,
        max_depth: typing.Optional[int] = OMIT,
        max_pages: typing.Optional[int] = OMIT,
        pattern: typing.Optional[str] = OMIT,
        sitemap_urls: typing.Optional[typing.Sequence[str]] = OMIT,
        parent_folder_id: typing.Optional[str] = OMIT,
        enable_auto_sync: typing.Optional[bool] = OMIT,
        auto_remove: typing.Optional[bool] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CreateCrawlJobResponseModel:
        """
        Create a crawl job to crawl the given URL with specified depth and page limits.

        Parameters
        ----------
        url : str
            URL to a page of documentation that the agent will have access to in order to interact with users.

        max_depth : typing.Optional[int]
            Maximum depth for crawling (1-5), defaults to 3.

        max_pages : typing.Optional[int]
            Maximum number of pages to crawl (1-10,000), defaults to 1000.

        pattern : typing.Optional[str]
            If set, only URLs that match this pattern are included.

        sitemap_urls : typing.Optional[typing.Sequence[str]]
            List of URLs to crawl from sitemap (optional, overrides automatic URL discovery).

        parent_folder_id : typing.Optional[str]
            If set, the created document or folder will be placed inside the given folder.

        enable_auto_sync : typing.Optional[bool]
            Whether to enable auto-sync for this URL document.

        auto_remove : typing.Optional[bool]
            Whether to automatically remove the document if the URL becomes unavailable. Only applicable when auto-sync is enabled.

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

        Returns
        -------
        CreateCrawlJobResponseModel
            Successful Response

        Examples
        --------
        from elevenlabs import ElevenLabs

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.conversational_ai.knowledge_base.crawl_jobs.create(
            url="url",
        )
        """
        _response = self._raw_client.create(
            url=url,
            max_depth=max_depth,
            max_pages=max_pages,
            pattern=pattern,
            sitemap_urls=sitemap_urls,
            parent_folder_id=parent_folder_id,
            enable_auto_sync=enable_auto_sync,
            auto_remove=auto_remove,
            request_options=request_options,
        )
        return _response.data

    def get(
        self, crawl_job_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> GetCrawlJobResponseModel:
        """
        Get details about a specific crawl job including status and progress.

        Parameters
        ----------
        crawl_job_id : str
            The id of the crawl job to retrieve

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

        Returns
        -------
        GetCrawlJobResponseModel
            Successful Response

        Examples
        --------
        from elevenlabs import ElevenLabs

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.conversational_ai.knowledge_base.crawl_jobs.get(
            crawl_job_id="crawl_job_id",
        )
        """
        _response = self._raw_client.get(crawl_job_id, request_options=request_options)
        return _response.data

    def cancel(self, crawl_job_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> typing.Any:
        """
        Cancel a crawl job and delete all associated documents and folders.

        Parameters
        ----------
        crawl_job_id : str
            The id of the crawl job to retrieve

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

        Returns
        -------
        typing.Any
            Successful Response

        Examples
        --------
        from elevenlabs import ElevenLabs

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.conversational_ai.knowledge_base.crawl_jobs.cancel(
            crawl_job_id="crawl_job_id",
        )
        """
        _response = self._raw_client.cancel(crawl_job_id, request_options=request_options)
        return _response.data


class AsyncCrawlJobsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawCrawlJobsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawCrawlJobsClient
        """
        return self._raw_client

    async def list(
        self,
        *,
        include_job_ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        page_size: typing.Optional[int] = None,
        cursor: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ListCrawlJobsResponseModel:
        """
        Get a list of ongoing and recent crawl jobs for the user.

        Parameters
        ----------
        include_job_ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            Ids of additional crawl jobs to retrieve

        page_size : typing.Optional[int]
            How many documents to return at maximum. Can not exceed 100, defaults to 30.

        cursor : typing.Optional[str]
            Used for fetching next page. Cursor is returned in the response.

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

        Returns
        -------
        ListCrawlJobsResponseModel
            Successful Response

        Examples
        --------
        import asyncio

        from elevenlabs import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.conversational_ai.knowledge_base.crawl_jobs.list(
                include_job_ids=["include_job_ids"],
                page_size=1,
                cursor="cursor",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.list(
            include_job_ids=include_job_ids, page_size=page_size, cursor=cursor, request_options=request_options
        )
        return _response.data

    async def create(
        self,
        *,
        url: str,
        max_depth: typing.Optional[int] = OMIT,
        max_pages: typing.Optional[int] = OMIT,
        pattern: typing.Optional[str] = OMIT,
        sitemap_urls: typing.Optional[typing.Sequence[str]] = OMIT,
        parent_folder_id: typing.Optional[str] = OMIT,
        enable_auto_sync: typing.Optional[bool] = OMIT,
        auto_remove: typing.Optional[bool] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CreateCrawlJobResponseModel:
        """
        Create a crawl job to crawl the given URL with specified depth and page limits.

        Parameters
        ----------
        url : str
            URL to a page of documentation that the agent will have access to in order to interact with users.

        max_depth : typing.Optional[int]
            Maximum depth for crawling (1-5), defaults to 3.

        max_pages : typing.Optional[int]
            Maximum number of pages to crawl (1-10,000), defaults to 1000.

        pattern : typing.Optional[str]
            If set, only URLs that match this pattern are included.

        sitemap_urls : typing.Optional[typing.Sequence[str]]
            List of URLs to crawl from sitemap (optional, overrides automatic URL discovery).

        parent_folder_id : typing.Optional[str]
            If set, the created document or folder will be placed inside the given folder.

        enable_auto_sync : typing.Optional[bool]
            Whether to enable auto-sync for this URL document.

        auto_remove : typing.Optional[bool]
            Whether to automatically remove the document if the URL becomes unavailable. Only applicable when auto-sync is enabled.

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

        Returns
        -------
        CreateCrawlJobResponseModel
            Successful Response

        Examples
        --------
        import asyncio

        from elevenlabs import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.conversational_ai.knowledge_base.crawl_jobs.create(
                url="url",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create(
            url=url,
            max_depth=max_depth,
            max_pages=max_pages,
            pattern=pattern,
            sitemap_urls=sitemap_urls,
            parent_folder_id=parent_folder_id,
            enable_auto_sync=enable_auto_sync,
            auto_remove=auto_remove,
            request_options=request_options,
        )
        return _response.data

    async def get(
        self, crawl_job_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> GetCrawlJobResponseModel:
        """
        Get details about a specific crawl job including status and progress.

        Parameters
        ----------
        crawl_job_id : str
            The id of the crawl job to retrieve

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

        Returns
        -------
        GetCrawlJobResponseModel
            Successful Response

        Examples
        --------
        import asyncio

        from elevenlabs import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.conversational_ai.knowledge_base.crawl_jobs.get(
                crawl_job_id="crawl_job_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.get(crawl_job_id, request_options=request_options)
        return _response.data

    async def cancel(self, crawl_job_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> typing.Any:
        """
        Cancel a crawl job and delete all associated documents and folders.

        Parameters
        ----------
        crawl_job_id : str
            The id of the crawl job to retrieve

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

        Returns
        -------
        typing.Any
            Successful Response

        Examples
        --------
        import asyncio

        from elevenlabs import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.conversational_ai.knowledge_base.crawl_jobs.cancel(
                crawl_job_id="crawl_job_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.cancel(crawl_job_id, request_options=request_options)
        return _response.data
