# 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_version import ExtractorVersion
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 AsyncRawExtractorVersionsClient, RawExtractorVersionsClient
from .types.extractor_versions_list_response import ExtractorVersionsListResponse

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


class ExtractorVersionsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawExtractorVersionsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawExtractorVersionsClient
        """
        return self._raw_client

    def list(
        self,
        extractor_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,
    ) -> ExtractorVersionsListResponse:
        """
        This endpoint allows you to fetch all versions of a given extractor, 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 extractor, which can be published to create a new version. It might not have any changes from the last published version.

        Parameters
        ----------
        extractor_id : str
            The ID of the extractor.

            Example: `"ex_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
        -------
        ExtractorVersionsListResponse
            Successfully retrieved extractor versions

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

        client = Extend(
            token="YOUR_TOKEN",
        )
        client.extractor_versions.list(
            extractor_id="extractor_id_here",
            next_page_token="xK9mLPqRtN3vS8wF5hB2cQ==:zWvUxYjM4nKpL7aDgE9HbTcR2mAyX3/Q+CNkfBSw1dZ=",
        )
        """
        _response = self._raw_client.list(
            extractor_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,
        extractor_id: str,
        *,
        release_type: ReleaseType,
        description: typing.Optional[VersionDescription] = OMIT,
        config: typing.Optional[ExtractConfigJsonParams] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ExtractorVersion:
        """
        This endpoint allows you to publish a new version of an existing extractor. Publishing a new version creates a snapshot of the extractor's current configuration and makes it available for use in workflows.

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

        Parameters
        ----------
        extractor_id : str
            The ID of the extractor.

            Example: `"ex_Xj8mK2pL9nR4vT7qY5wZ"`

        release_type : ReleaseType

        description : typing.Optional[VersionDescription]

        config : typing.Optional[ExtractConfigJsonParams]
            The configuration for this version of the extractor.

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

        Returns
        -------
        ExtractorVersion
            Successfully published extractor version

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

        client = Extend(
            token="YOUR_TOKEN",
        )
        client.extractor_versions.create(
            extractor_id="extractor_id_here",
            release_type=ReleaseType.MAJOR,
        )
        """
        _response = self._raw_client.create(
            extractor_id,
            release_type=release_type,
            description=description,
            config=config,
            request_options=request_options,
        )
        return _response.data

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

        Parameters
        ----------
        extractor_id : str
            The ID of the extractor.

            Example: `"ex_Xj8mK2pL9nR4vT7qY5wZ"`

        version_id : str
            The ID of the specific extractor version.

            Example: `"extv_QYk6jgHA_8CsO8rVWhyNC"`

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

        Returns
        -------
        ExtractorVersion
            Successfully retrieved extractor version

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

        client = Extend(
            token="YOUR_TOKEN",
        )
        client.extractor_versions.retrieve(
            extractor_id="extractor_id_here",
            version_id="extractor_version_id_here",
        )
        """
        _response = self._raw_client.retrieve(extractor_id, version_id, request_options=request_options)
        return _response.data


class AsyncExtractorVersionsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawExtractorVersionsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawExtractorVersionsClient
        """
        return self._raw_client

    async def list(
        self,
        extractor_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,
    ) -> ExtractorVersionsListResponse:
        """
        This endpoint allows you to fetch all versions of a given extractor, 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 extractor, which can be published to create a new version. It might not have any changes from the last published version.

        Parameters
        ----------
        extractor_id : str
            The ID of the extractor.

            Example: `"ex_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
        -------
        ExtractorVersionsListResponse
            Successfully retrieved extractor versions

        Examples
        --------
        import asyncio

        from extend_ai import AsyncExtend

        client = AsyncExtend(
            token="YOUR_TOKEN",
        )


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


        asyncio.run(main())
        """
        _response = await self._raw_client.list(
            extractor_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,
        extractor_id: str,
        *,
        release_type: ReleaseType,
        description: typing.Optional[VersionDescription] = OMIT,
        config: typing.Optional[ExtractConfigJsonParams] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ExtractorVersion:
        """
        This endpoint allows you to publish a new version of an existing extractor. Publishing a new version creates a snapshot of the extractor's current configuration and makes it available for use in workflows.

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

        Parameters
        ----------
        extractor_id : str
            The ID of the extractor.

            Example: `"ex_Xj8mK2pL9nR4vT7qY5wZ"`

        release_type : ReleaseType

        description : typing.Optional[VersionDescription]

        config : typing.Optional[ExtractConfigJsonParams]
            The configuration for this version of the extractor.

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

        Returns
        -------
        ExtractorVersion
            Successfully published extractor version

        Examples
        --------
        import asyncio

        from extend_ai import AsyncExtend, ReleaseType

        client = AsyncExtend(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.extractor_versions.create(
                extractor_id="extractor_id_here",
                release_type=ReleaseType.MAJOR,
            )


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

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

        Parameters
        ----------
        extractor_id : str
            The ID of the extractor.

            Example: `"ex_Xj8mK2pL9nR4vT7qY5wZ"`

        version_id : str
            The ID of the specific extractor version.

            Example: `"extv_QYk6jgHA_8CsO8rVWhyNC"`

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

        Returns
        -------
        ExtractorVersion
            Successfully retrieved extractor version

        Examples
        --------
        import asyncio

        from extend_ai import AsyncExtend

        client = AsyncExtend(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.extractor_versions.retrieve(
                extractor_id="extractor_id_here",
                version_id="extractor_version_id_here",
            )


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