# 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.classify_config import ClassifyConfigParams
from ..types.classifier import Classifier
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 AsyncRawClassifiersClient, RawClassifiersClient
from .types.classifiers_list_response import ClassifiersListResponse

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


class ClassifiersClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawClassifiersClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawClassifiersClient
        """
        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,
    ) -> ClassifiersListResponse:
        """
        List all classifiers.

        Returns a summary of each classifier. Use `GET /classifiers/{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
        -------
        ClassifiersListResponse
            Successfully retrieved classifiers

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

        client = Extend(
            token="YOUR_TOKEN",
        )
        client.classifiers.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_classifier_id: typing.Optional[str] = OMIT,
        config: typing.Optional[ClassifyConfigParams] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> Classifier:
        """
        Create a new classifier.

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

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

            Example: `"cl_BMdfq_yWM3sT-ZzvCnA3f"`

        config : typing.Optional[ClassifyConfigParams]
            The configuration for the classifier. Cannot be provided together with `cloneClassifierId`.

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

        Returns
        -------
        Classifier
            Classifier created successfully

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

        client = Extend(
            token="YOUR_TOKEN",
        )
        client.classifiers.create(
            name="Document Classifier",
            config={
                "classifications": [
                    {
                        "id": "invoice",
                        "type": "invoice",
                        "description": "An invoice or bill for goods or services",
                    },
                    {
                        "id": "receipt",
                        "type": "receipt",
                        "description": "A receipt confirming payment",
                    },
                    {
                        "id": "other",
                        "type": "other",
                        "description": "Any other document type",
                    },
                ]
            },
        )
        """
        _response = self._raw_client.create(
            name=name, clone_classifier_id=clone_classifier_id, config=config, request_options=request_options
        )
        return _response.data

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

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

            Example: `"cl_Xj8mK2pL9nR4vT7qY5wZ"`

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

        Returns
        -------
        Classifier
            Classifier details

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

        client = Extend(
            token="YOUR_TOKEN",
        )
        client.classifiers.retrieve(
            id="classifier_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[ClassifyConfigParams] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> Classifier:
        """
        Update an existing classifier.

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

            Example: `"cl_Xj8mK2pL9nR4vT7qY5wZ"`

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

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

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

        Returns
        -------
        Classifier
            Classifier updated successfully

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

        client = Extend(
            token="YOUR_TOKEN",
        )
        client.classifiers.update(
            id="classifier_id_here",
            name="Document Classifier v2",
        )
        """
        _response = self._raw_client.update(id, name=name, config=config, request_options=request_options)
        return _response.data


class AsyncClassifiersClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawClassifiersClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawClassifiersClient
        """
        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,
    ) -> ClassifiersListResponse:
        """
        List all classifiers.

        Returns a summary of each classifier. Use `GET /classifiers/{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
        -------
        ClassifiersListResponse
            Successfully retrieved classifiers

        Examples
        --------
        import asyncio

        from extend_ai import AsyncExtend

        client = AsyncExtend(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.classifiers.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_classifier_id: typing.Optional[str] = OMIT,
        config: typing.Optional[ClassifyConfigParams] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> Classifier:
        """
        Create a new classifier.

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

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

            Example: `"cl_BMdfq_yWM3sT-ZzvCnA3f"`

        config : typing.Optional[ClassifyConfigParams]
            The configuration for the classifier. Cannot be provided together with `cloneClassifierId`.

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

        Returns
        -------
        Classifier
            Classifier created successfully

        Examples
        --------
        import asyncio

        from extend_ai import AsyncExtend

        client = AsyncExtend(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.classifiers.create(
                name="Document Classifier",
                config={
                    "classifications": [
                        {
                            "id": "invoice",
                            "type": "invoice",
                            "description": "An invoice or bill for goods or services",
                        },
                        {
                            "id": "receipt",
                            "type": "receipt",
                            "description": "A receipt confirming payment",
                        },
                        {
                            "id": "other",
                            "type": "other",
                            "description": "Any other document type",
                        },
                    ]
                },
            )


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

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

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

            Example: `"cl_Xj8mK2pL9nR4vT7qY5wZ"`

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

        Returns
        -------
        Classifier
            Classifier details

        Examples
        --------
        import asyncio

        from extend_ai import AsyncExtend

        client = AsyncExtend(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.classifiers.retrieve(
                id="classifier_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[ClassifyConfigParams] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> Classifier:
        """
        Update an existing classifier.

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

            Example: `"cl_Xj8mK2pL9nR4vT7qY5wZ"`

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

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

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

        Returns
        -------
        Classifier
            Classifier updated successfully

        Examples
        --------
        import asyncio

        from extend_ai import AsyncExtend

        client = AsyncExtend(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.classifiers.update(
                id="classifier_id_here",
                name="Document Classifier v2",
            )


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