# 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 ..types.batch_progress_response import BatchProgressResponse
from ..types.batch_results_response import BatchResultsResponse
from .raw_client import AsyncRawBatchClient, RawBatchClient


class BatchClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawBatchClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawBatchClient
        """
        return self._raw_client

    def get_batch_id_progress(
        self, id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> BatchProgressResponse:
        """
        Returns the current progress of a batch operation. Poll this endpoint until `status` is `completed`. When completed, a `results_url` is included. If all tasks failed, an `error` field is included with the failure reason.

        Parameters
        ----------
        id : str
            The batch ID returned from the initiating bulk operation

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

        Returns
        -------
        BatchProgressResponse
            Successful response with current batch progress

        Examples
        --------
        from ottimate import OttimateApi

        client = OttimateApi(
            api_key="YOUR_API_KEY",
            api_version="YOUR_API_VERSION",
            api_key="YOUR_API_KEY",
        )
        client.batch.get_batch_id_progress(
            id="racc_90832490382904802384",
        )
        """
        _response = self._raw_client.get_batch_id_progress(id, request_options=request_options)
        return _response.data

    def get_batch_id_results(
        self, id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> BatchResultsResponse:
        """
        Returns the per-task results for a batch operation. Call this endpoint after polling `/progress` until `status` is `completed`. Each entry in `results` corresponds to one task, with the task outcome in `result` and any error message in `message`.

        Parameters
        ----------
        id : str
            The batch ID returned from the initiating bulk operation

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

        Returns
        -------
        BatchResultsResponse
            Successful response with batch results

        Examples
        --------
        from ottimate import OttimateApi

        client = OttimateApi(
            api_key="YOUR_API_KEY",
            api_version="YOUR_API_VERSION",
            api_key="YOUR_API_KEY",
        )
        client.batch.get_batch_id_results(
            id="racc_90832490382904802384",
        )
        """
        _response = self._raw_client.get_batch_id_results(id, request_options=request_options)
        return _response.data


class AsyncBatchClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawBatchClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawBatchClient
        """
        return self._raw_client

    async def get_batch_id_progress(
        self, id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> BatchProgressResponse:
        """
        Returns the current progress of a batch operation. Poll this endpoint until `status` is `completed`. When completed, a `results_url` is included. If all tasks failed, an `error` field is included with the failure reason.

        Parameters
        ----------
        id : str
            The batch ID returned from the initiating bulk operation

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

        Returns
        -------
        BatchProgressResponse
            Successful response with current batch progress

        Examples
        --------
        import asyncio

        from ottimate import AsyncOttimateApi

        client = AsyncOttimateApi(
            api_key="YOUR_API_KEY",
            api_version="YOUR_API_VERSION",
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.batch.get_batch_id_progress(
                id="racc_90832490382904802384",
            )


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

    async def get_batch_id_results(
        self, id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> BatchResultsResponse:
        """
        Returns the per-task results for a batch operation. Call this endpoint after polling `/progress` until `status` is `completed`. Each entry in `results` corresponds to one task, with the task outcome in `result` and any error message in `message`.

        Parameters
        ----------
        id : str
            The batch ID returned from the initiating bulk operation

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

        Returns
        -------
        BatchResultsResponse
            Successful response with batch results

        Examples
        --------
        import asyncio

        from ottimate import AsyncOttimateApi

        client = AsyncOttimateApi(
            api_key="YOUR_API_KEY",
            api_version="YOUR_API_VERSION",
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.batch.get_batch_id_results(
                id="racc_90832490382904802384",
            )


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