# 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 ..requests.extract_config_json import ExtractConfigJsonParams
from ..types.extractor import Extractor
from ..types.max_page_size import MaxPageSize
from ..types.next_page_token import NextPageToken
from ..types.sort_by import SortBy
from ..types.sort_dir import SortDir
from .raw_client import AsyncRawExtractorsClient, RawExtractorsClient
from .types.extractors_list_response import ExtractorsListResponse

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


class ExtractorsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawExtractorsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawExtractorsClient
        """
        return self._raw_client

    def list(
        self,
        *,
        next_page_token: typing.Optional[NextPageToken] = None,
        max_page_size: typing.Optional[MaxPageSize] = None,
        sort_by: typing.Optional[SortBy] = None,
        sort_dir: typing.Optional[SortDir] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ExtractorsListResponse:
        """
        List all extractors.

        Returns a summary of each extractor. Use `GET /extractors/{id}` to retrieve the full object including `draftVersion`.

        Parameters
        ----------
        next_page_token : typing.Optional[NextPageToken]

        max_page_size : typing.Optional[MaxPageSize]

        sort_by : typing.Optional[SortBy]

        sort_dir : typing.Optional[SortDir]

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

        Returns
        -------
        ExtractorsListResponse
            Successfully retrieved extractors

        Examples
        --------
        from extend_ai import Extend

        client = Extend(
            token="YOUR_TOKEN",
        )
        client.extractors.list(
            next_page_token="xK9mLPqRtN3vS8wF5hB2cQ==:zWvUxYjM4nKpL7aDgE9HbTcR2mAyX3/Q+CNkfBSw1dZ=",
        )
        """
        _response = self._raw_client.list(
            next_page_token=next_page_token,
            max_page_size=max_page_size,
            sort_by=sort_by,
            sort_dir=sort_dir,
            request_options=request_options,
        )
        return _response.data

    def create(
        self,
        *,
        name: str,
        clone_extractor_id: typing.Optional[str] = OMIT,
        config: typing.Optional[ExtractConfigJsonParams] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> Extractor:
        """
        Create a new extractor.

        Parameters
        ----------
        name : str
            The name of the extractor.

        clone_extractor_id : typing.Optional[str]
            The ID of an existing extractor to clone. If provided, the new extractor will be created with the same config as the extractor with this ID. Cannot be provided together with `config`.

            Example: `"ex_BMdfq_yWM3sT-ZzvCnA3f"`

        config : typing.Optional[ExtractConfigJsonParams]
            The configuration for the extractor. Cannot be provided together with `cloneExtractorId`.

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

        Returns
        -------
        Extractor
            Extractor created successfully

        Examples
        --------
        from extend_ai import Extend

        client = Extend(
            token="YOUR_TOKEN",
        )
        client.extractors.create(
            name="Invoice Extractor",
            config={
                "schema": {
                    "type": "object",
                    "properties": {
                        "vendor_name": {
                            "type": "string",
                            "description": "The name of the vendor",
                        },
                        "invoice_number": {
                            "type": "string",
                            "description": "The invoice number",
                        },
                        "total_amount": {
                            "type": "number",
                            "description": "The total amount due",
                        },
                    },
                }
            },
        )
        """
        _response = self._raw_client.create(
            name=name, clone_extractor_id=clone_extractor_id, config=config, request_options=request_options
        )
        return _response.data

    def retrieve(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> Extractor:
        """
        Get details of an extractor.

        Parameters
        ----------
        id : str
            The ID of the extractor to get.

            Example: `"ex_Xj8mK2pL9nR4vT7qY5wZ"`

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

        Returns
        -------
        Extractor
            Extractor details

        Examples
        --------
        from extend_ai import Extend

        client = Extend(
            token="YOUR_TOKEN",
        )
        client.extractors.retrieve(
            id="extractor_id_here",
        )
        """
        _response = self._raw_client.retrieve(id, request_options=request_options)
        return _response.data

    def update(
        self,
        id: str,
        *,
        name: typing.Optional[str] = OMIT,
        config: typing.Optional[ExtractConfigJsonParams] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> Extractor:
        """
        Update an existing extractor.

        Parameters
        ----------
        id : str
            The ID of the extractor to update.

            Example: `"ex_Xj8mK2pL9nR4vT7qY5wZ"`

        name : typing.Optional[str]
            The new name of the extractor.

        config : typing.Optional[ExtractConfigJsonParams]
            The new configuration for the extractor. This will update the draft version of the extractor.

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

        Returns
        -------
        Extractor
            Extractor updated successfully

        Examples
        --------
        from extend_ai import Extend

        client = Extend(
            token="YOUR_TOKEN",
        )
        client.extractors.update(
            id="extractor_id_here",
            name="Invoice Extractor v2",
        )
        """
        _response = self._raw_client.update(id, name=name, config=config, request_options=request_options)
        return _response.data


class AsyncExtractorsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawExtractorsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawExtractorsClient
        """
        return self._raw_client

    async def list(
        self,
        *,
        next_page_token: typing.Optional[NextPageToken] = None,
        max_page_size: typing.Optional[MaxPageSize] = None,
        sort_by: typing.Optional[SortBy] = None,
        sort_dir: typing.Optional[SortDir] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ExtractorsListResponse:
        """
        List all extractors.

        Returns a summary of each extractor. Use `GET /extractors/{id}` to retrieve the full object including `draftVersion`.

        Parameters
        ----------
        next_page_token : typing.Optional[NextPageToken]

        max_page_size : typing.Optional[MaxPageSize]

        sort_by : typing.Optional[SortBy]

        sort_dir : typing.Optional[SortDir]

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

        Returns
        -------
        ExtractorsListResponse
            Successfully retrieved extractors

        Examples
        --------
        import asyncio

        from extend_ai import AsyncExtend

        client = AsyncExtend(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.extractors.list(
                next_page_token="xK9mLPqRtN3vS8wF5hB2cQ==:zWvUxYjM4nKpL7aDgE9HbTcR2mAyX3/Q+CNkfBSw1dZ=",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.list(
            next_page_token=next_page_token,
            max_page_size=max_page_size,
            sort_by=sort_by,
            sort_dir=sort_dir,
            request_options=request_options,
        )
        return _response.data

    async def create(
        self,
        *,
        name: str,
        clone_extractor_id: typing.Optional[str] = OMIT,
        config: typing.Optional[ExtractConfigJsonParams] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> Extractor:
        """
        Create a new extractor.

        Parameters
        ----------
        name : str
            The name of the extractor.

        clone_extractor_id : typing.Optional[str]
            The ID of an existing extractor to clone. If provided, the new extractor will be created with the same config as the extractor with this ID. Cannot be provided together with `config`.

            Example: `"ex_BMdfq_yWM3sT-ZzvCnA3f"`

        config : typing.Optional[ExtractConfigJsonParams]
            The configuration for the extractor. Cannot be provided together with `cloneExtractorId`.

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

        Returns
        -------
        Extractor
            Extractor created successfully

        Examples
        --------
        import asyncio

        from extend_ai import AsyncExtend

        client = AsyncExtend(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.extractors.create(
                name="Invoice Extractor",
                config={
                    "schema": {
                        "type": "object",
                        "properties": {
                            "vendor_name": {
                                "type": "string",
                                "description": "The name of the vendor",
                            },
                            "invoice_number": {
                                "type": "string",
                                "description": "The invoice number",
                            },
                            "total_amount": {
                                "type": "number",
                                "description": "The total amount due",
                            },
                        },
                    }
                },
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create(
            name=name, clone_extractor_id=clone_extractor_id, config=config, request_options=request_options
        )
        return _response.data

    async def retrieve(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> Extractor:
        """
        Get details of an extractor.

        Parameters
        ----------
        id : str
            The ID of the extractor to get.

            Example: `"ex_Xj8mK2pL9nR4vT7qY5wZ"`

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

        Returns
        -------
        Extractor
            Extractor details

        Examples
        --------
        import asyncio

        from extend_ai import AsyncExtend

        client = AsyncExtend(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.extractors.retrieve(
                id="extractor_id_here",
            )


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

    async def update(
        self,
        id: str,
        *,
        name: typing.Optional[str] = OMIT,
        config: typing.Optional[ExtractConfigJsonParams] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> Extractor:
        """
        Update an existing extractor.

        Parameters
        ----------
        id : str
            The ID of the extractor to update.

            Example: `"ex_Xj8mK2pL9nR4vT7qY5wZ"`

        name : typing.Optional[str]
            The new name of the extractor.

        config : typing.Optional[ExtractConfigJsonParams]
            The new configuration for the extractor. This will update the draft version of the extractor.

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

        Returns
        -------
        Extractor
            Extractor updated successfully

        Examples
        --------
        import asyncio

        from extend_ai import AsyncExtend

        client = AsyncExtend(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.extractors.update(
                id="extractor_id_here",
                name="Invoice Extractor v2",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.update(id, name=name, config=config, request_options=request_options)
        return _response.data
