# 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_version import ClassifierVersion
from ..types.max_page_size import MaxPageSize
from ..types.next_page_token import NextPageToken
from ..types.release_type import ReleaseType
from ..types.sort_dir import SortDir
from ..types.version_description import VersionDescription
from .raw_client import AsyncRawClassifierVersionsClient, RawClassifierVersionsClient
from .types.classifier_versions_list_response import ClassifierVersionsListResponse

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


class ClassifierVersionsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawClassifierVersionsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawClassifierVersionsClient
        """
        return self._raw_client

    def list(
        self,
        classifier_id: str,
        *,
        sort_dir: typing.Optional[SortDir] = None,
        next_page_token: typing.Optional[NextPageToken] = None,
        max_page_size: typing.Optional[MaxPageSize] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ClassifierVersionsListResponse:
        """
        This endpoint allows you to fetch all versions of a given classifier, including the current `draft` version.

        Versions are returned in descending order of creation (newest first) with the `draft` version first. The `draft` version is the latest unpublished version of the classifier, which can be published to create a new version. It might not have any changes from the last published version.

        Parameters
        ----------
        classifier_id : str
            The ID of the classifier.

            Example: `"cl_Xj8mK2pL9nR4vT7qY5wZ"`

        sort_dir : typing.Optional[SortDir]

        next_page_token : typing.Optional[NextPageToken]

        max_page_size : typing.Optional[MaxPageSize]

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

        Returns
        -------
        ClassifierVersionsListResponse
            Successfully retrieved classifier versions

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

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

    def create(
        self,
        classifier_id: str,
        *,
        release_type: ReleaseType,
        description: typing.Optional[VersionDescription] = OMIT,
        config: typing.Optional[ClassifyConfigParams] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ClassifierVersion:
        """
        This endpoint allows you to publish a new version of an existing classifier. Publishing a new version creates a snapshot of the classifier's current configuration and makes it available for use in workflows.

        Publishing a new version does not automatically update existing workflows using this classifier. You may need to manually update workflows to use the new version if desired.

        Parameters
        ----------
        classifier_id : str
            The ID of the classifier.

            Example: `"cl_Xj8mK2pL9nR4vT7qY5wZ"`

        release_type : ReleaseType

        description : typing.Optional[VersionDescription]

        config : typing.Optional[ClassifyConfigParams]
            The configuration for this version of the classifier.

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

        Returns
        -------
        ClassifierVersion
            Successfully published classifier version

        Examples
        --------
        from extend_ai import Extend, ReleaseType

        client = Extend(
            token="YOUR_TOKEN",
        )
        client.classifier_versions.create(
            classifier_id="classifier_id_here",
            release_type=ReleaseType.MINOR,
            description="Added new document classification type",
        )
        """
        _response = self._raw_client.create(
            classifier_id,
            release_type=release_type,
            description=description,
            config=config,
            request_options=request_options,
        )
        return _response.data

    def retrieve(
        self, classifier_id: str, version_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> ClassifierVersion:
        """
        Retrieve a specific version of a classifier in Extend

        Parameters
        ----------
        classifier_id : str
            The ID of the classifier.

            Example: `"cl_Xj8mK2pL9nR4vT7qY5wZ"`

        version_id : str
            The ID of the specific classifier version.

            Example: `"clsv_QYk6jgHA_8CsO8rVWhyNC"`

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

        Returns
        -------
        ClassifierVersion
            Successfully retrieved classifier version

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

        client = Extend(
            token="YOUR_TOKEN",
        )
        client.classifier_versions.retrieve(
            classifier_id="classifier_id_here",
            version_id="classifier_version_id_here",
        )
        """
        _response = self._raw_client.retrieve(classifier_id, version_id, request_options=request_options)
        return _response.data


class AsyncClassifierVersionsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawClassifierVersionsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawClassifierVersionsClient
        """
        return self._raw_client

    async def list(
        self,
        classifier_id: str,
        *,
        sort_dir: typing.Optional[SortDir] = None,
        next_page_token: typing.Optional[NextPageToken] = None,
        max_page_size: typing.Optional[MaxPageSize] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ClassifierVersionsListResponse:
        """
        This endpoint allows you to fetch all versions of a given classifier, including the current `draft` version.

        Versions are returned in descending order of creation (newest first) with the `draft` version first. The `draft` version is the latest unpublished version of the classifier, which can be published to create a new version. It might not have any changes from the last published version.

        Parameters
        ----------
        classifier_id : str
            The ID of the classifier.

            Example: `"cl_Xj8mK2pL9nR4vT7qY5wZ"`

        sort_dir : typing.Optional[SortDir]

        next_page_token : typing.Optional[NextPageToken]

        max_page_size : typing.Optional[MaxPageSize]

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

        Returns
        -------
        ClassifierVersionsListResponse
            Successfully retrieved classifier versions

        Examples
        --------
        import asyncio

        from extend_ai import AsyncExtend

        client = AsyncExtend(
            token="YOUR_TOKEN",
        )


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


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

    async def create(
        self,
        classifier_id: str,
        *,
        release_type: ReleaseType,
        description: typing.Optional[VersionDescription] = OMIT,
        config: typing.Optional[ClassifyConfigParams] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ClassifierVersion:
        """
        This endpoint allows you to publish a new version of an existing classifier. Publishing a new version creates a snapshot of the classifier's current configuration and makes it available for use in workflows.

        Publishing a new version does not automatically update existing workflows using this classifier. You may need to manually update workflows to use the new version if desired.

        Parameters
        ----------
        classifier_id : str
            The ID of the classifier.

            Example: `"cl_Xj8mK2pL9nR4vT7qY5wZ"`

        release_type : ReleaseType

        description : typing.Optional[VersionDescription]

        config : typing.Optional[ClassifyConfigParams]
            The configuration for this version of the classifier.

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

        Returns
        -------
        ClassifierVersion
            Successfully published classifier version

        Examples
        --------
        import asyncio

        from extend_ai import AsyncExtend, ReleaseType

        client = AsyncExtend(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.classifier_versions.create(
                classifier_id="classifier_id_here",
                release_type=ReleaseType.MINOR,
                description="Added new document classification type",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create(
            classifier_id,
            release_type=release_type,
            description=description,
            config=config,
            request_options=request_options,
        )
        return _response.data

    async def retrieve(
        self, classifier_id: str, version_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> ClassifierVersion:
        """
        Retrieve a specific version of a classifier in Extend

        Parameters
        ----------
        classifier_id : str
            The ID of the classifier.

            Example: `"cl_Xj8mK2pL9nR4vT7qY5wZ"`

        version_id : str
            The ID of the specific classifier version.

            Example: `"clsv_QYk6jgHA_8CsO8rVWhyNC"`

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

        Returns
        -------
        ClassifierVersion
            Successfully retrieved classifier version

        Examples
        --------
        import asyncio

        from extend_ai import AsyncExtend

        client = AsyncExtend(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.classifier_versions.retrieve(
                classifier_id="classifier_id_here",
                version_id="classifier_version_id_here",
            )


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