# This file was auto-generated by Fern from our API Definition.

from ..core.client_wrapper import SyncClientWrapper
import typing
from ..core.request_options import RequestOptions
from ..types.configurable_transformation_definition import ConfigurableTransformationDefinition
from ..core.pydantic_utilities import parse_obj_as
from json.decoder import JSONDecodeError
from ..core.api_error import ApiError
from ..types.data_source_definition import DataSourceDefinition
from ..types.data_sink_definition import DataSinkDefinition
from ..core.client_wrapper import AsyncClientWrapper


class ComponentDefinitionsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._client_wrapper = client_wrapper

    def list_transformation_definitions(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.List[ConfigurableTransformationDefinition]:
        """
        List transformation component definitions.

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

        Returns
        -------
        typing.List[ConfigurableTransformationDefinition]
            Successful Response

        Examples
        --------
        from llama_index import LlamaCloud

        client = LlamaCloud(
            token="YOUR_TOKEN",
        )
        client.component_definitions.list_transformation_definitions()
        """
        _response = self._client_wrapper.httpx_client.request(
            "api/v1/component-definition/configurable-transformations",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    typing.List[ConfigurableTransformationDefinition],
                    parse_obj_as(
                        type_=typing.List[ConfigurableTransformationDefinition],  # type: ignore
                        object_=_response.json(),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    def list_data_source_definitions(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.List[DataSourceDefinition]:
        """
        List data source component definitions.

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

        Returns
        -------
        typing.List[DataSourceDefinition]
            Successful Response

        Examples
        --------
        from llama_index import LlamaCloud

        client = LlamaCloud(
            token="YOUR_TOKEN",
        )
        client.component_definitions.list_data_source_definitions()
        """
        _response = self._client_wrapper.httpx_client.request(
            "api/v1/component-definition/data-sources",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    typing.List[DataSourceDefinition],
                    parse_obj_as(
                        type_=typing.List[DataSourceDefinition],  # type: ignore
                        object_=_response.json(),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    def list_data_sink_definitions(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.List[DataSinkDefinition]:
        """
        List data sink component definitions.

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

        Returns
        -------
        typing.List[DataSinkDefinition]
            Successful Response

        Examples
        --------
        from llama_index import LlamaCloud

        client = LlamaCloud(
            token="YOUR_TOKEN",
        )
        client.component_definitions.list_data_sink_definitions()
        """
        _response = self._client_wrapper.httpx_client.request(
            "api/v1/component-definition/data-sinks",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    typing.List[DataSinkDefinition],
                    parse_obj_as(
                        type_=typing.List[DataSinkDefinition],  # type: ignore
                        object_=_response.json(),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)


class AsyncComponentDefinitionsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._client_wrapper = client_wrapper

    async def list_transformation_definitions(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.List[ConfigurableTransformationDefinition]:
        """
        List transformation component definitions.

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

        Returns
        -------
        typing.List[ConfigurableTransformationDefinition]
            Successful Response

        Examples
        --------
        import asyncio

        from llama_index import AsyncLlamaCloud

        client = AsyncLlamaCloud(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.component_definitions.list_transformation_definitions()


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            "api/v1/component-definition/configurable-transformations",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    typing.List[ConfigurableTransformationDefinition],
                    parse_obj_as(
                        type_=typing.List[ConfigurableTransformationDefinition],  # type: ignore
                        object_=_response.json(),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    async def list_data_source_definitions(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.List[DataSourceDefinition]:
        """
        List data source component definitions.

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

        Returns
        -------
        typing.List[DataSourceDefinition]
            Successful Response

        Examples
        --------
        import asyncio

        from llama_index import AsyncLlamaCloud

        client = AsyncLlamaCloud(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.component_definitions.list_data_source_definitions()


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            "api/v1/component-definition/data-sources",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    typing.List[DataSourceDefinition],
                    parse_obj_as(
                        type_=typing.List[DataSourceDefinition],  # type: ignore
                        object_=_response.json(),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    async def list_data_sink_definitions(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.List[DataSinkDefinition]:
        """
        List data sink component definitions.

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

        Returns
        -------
        typing.List[DataSinkDefinition]
            Successful Response

        Examples
        --------
        import asyncio

        from llama_index import AsyncLlamaCloud

        client = AsyncLlamaCloud(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.component_definitions.list_data_sink_definitions()


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            "api/v1/component-definition/data-sinks",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    typing.List[DataSinkDefinition],
                    parse_obj_as(
                        type_=typing.List[DataSinkDefinition],  # type: ignore
                        object_=_response.json(),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)
