# 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.split_config import SplitConfigParams
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 ..types.splitter import Splitter
from .raw_client import AsyncRawSplittersClient, RawSplittersClient
from .types.splitters_list_response import SplittersListResponse

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


class SplittersClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawSplittersClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawSplittersClient
        """
        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,
    ) -> SplittersListResponse:
        """
        List all splitters.

        Returns a summary of each splitter. Use `GET /splitters/{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
        -------
        SplittersListResponse
            Successfully retrieved splitters

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

        client = Extend(
            token="YOUR_TOKEN",
        )
        client.splitters.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_splitter_id: typing.Optional[str] = OMIT,
        config: typing.Optional[SplitConfigParams] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> Splitter:
        """
        Create a new splitter.

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

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

            Example: `"spl_BMdfq_yWM3sT-ZzvCnA3f"`

        config : typing.Optional[SplitConfigParams]
            The configuration for the splitter. Cannot be provided together with `cloneSplitterId`.

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

        Returns
        -------
        Splitter
            Splitter created successfully

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

        client = Extend(
            token="YOUR_TOKEN",
        )
        client.splitters.create(
            name="Document Splitter",
            config={
                "split_classifications": [
                    {
                        "id": "invoice",
                        "type": "invoice",
                        "description": "An invoice or bill for goods or services",
                        "identifier_key": "invoice number from the document header",
                    },
                    {
                        "id": "receipt",
                        "type": "receipt",
                        "description": "A receipt confirming payment",
                        "identifier_key": "receipt number",
                    },
                    {
                        "id": "other",
                        "type": "other",
                        "description": "Any other document type",
                    },
                ]
            },
        )
        """
        _response = self._raw_client.create(
            name=name, clone_splitter_id=clone_splitter_id, config=config, request_options=request_options
        )
        return _response.data

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

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

            Example: `"spl_Xj8mK2pL9nR4vT7qY5wZ"`

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

        Returns
        -------
        Splitter
            Splitter details

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

        client = Extend(
            token="YOUR_TOKEN",
        )
        client.splitters.retrieve(
            id="splitter_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[SplitConfigParams] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> Splitter:
        """
        Update an existing splitter.

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

            Example: `"spl_Xj8mK2pL9nR4vT7qY5wZ"`

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

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

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

        Returns
        -------
        Splitter
            Splitter updated successfully

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

        client = Extend(
            token="YOUR_TOKEN",
        )
        client.splitters.update(
            id="splitter_id_here",
            name="Document Splitter v2",
        )
        """
        _response = self._raw_client.update(id, name=name, config=config, request_options=request_options)
        return _response.data


class AsyncSplittersClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawSplittersClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawSplittersClient
        """
        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,
    ) -> SplittersListResponse:
        """
        List all splitters.

        Returns a summary of each splitter. Use `GET /splitters/{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
        -------
        SplittersListResponse
            Successfully retrieved splitters

        Examples
        --------
        import asyncio

        from extend_ai import AsyncExtend

        client = AsyncExtend(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.splitters.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_splitter_id: typing.Optional[str] = OMIT,
        config: typing.Optional[SplitConfigParams] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> Splitter:
        """
        Create a new splitter.

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

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

            Example: `"spl_BMdfq_yWM3sT-ZzvCnA3f"`

        config : typing.Optional[SplitConfigParams]
            The configuration for the splitter. Cannot be provided together with `cloneSplitterId`.

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

        Returns
        -------
        Splitter
            Splitter created successfully

        Examples
        --------
        import asyncio

        from extend_ai import AsyncExtend

        client = AsyncExtend(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.splitters.create(
                name="Document Splitter",
                config={
                    "split_classifications": [
                        {
                            "id": "invoice",
                            "type": "invoice",
                            "description": "An invoice or bill for goods or services",
                            "identifier_key": "invoice number from the document header",
                        },
                        {
                            "id": "receipt",
                            "type": "receipt",
                            "description": "A receipt confirming payment",
                            "identifier_key": "receipt number",
                        },
                        {
                            "id": "other",
                            "type": "other",
                            "description": "Any other document type",
                        },
                    ]
                },
            )


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

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

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

            Example: `"spl_Xj8mK2pL9nR4vT7qY5wZ"`

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

        Returns
        -------
        Splitter
            Splitter details

        Examples
        --------
        import asyncio

        from extend_ai import AsyncExtend

        client = AsyncExtend(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.splitters.retrieve(
                id="splitter_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[SplitConfigParams] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> Splitter:
        """
        Update an existing splitter.

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

            Example: `"spl_Xj8mK2pL9nR4vT7qY5wZ"`

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

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

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

        Returns
        -------
        Splitter
            Splitter updated successfully

        Examples
        --------
        import asyncio

        from extend_ai import AsyncExtend

        client = AsyncExtend(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.splitters.update(
                id="splitter_id_here",
                name="Document Splitter v2",
            )


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