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

import typing
from ..core.client_wrapper import SyncClientWrapper
import uuid
from ..core.request_options import RequestOptions
from .types.transcript_summary_response import TranscriptSummaryResponse
from ..core.jsonable_encoder import jsonable_encoder
from ..core.pydantic_utilities import parse_obj_as
from ..transcribe.errors.transcription_not_found import TranscriptionNotFound
from ..transcribe.errors.authentication_error import AuthenticationError
from json.decoder import JSONDecodeError
from ..core.api_error import ApiError
from ..core.client_wrapper import AsyncClientWrapper

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


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

    def generate_summary(
        self,
        transcription_id_: uuid.UUID,
        *,
        transcription_id: uuid.UUID,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> TranscriptSummaryResponse:
        """
        Generate a Markdown summary for a transcription. If a summary already exists, it is returned.

        Parameters
        ----------
        transcription_id_ : uuid.UUID
            ID of the transcription to summarize

        transcription_id : uuid.UUID
            ID of the transcription to summarize

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

        Returns
        -------
        TranscriptSummaryResponse

        Examples
        --------
        import uuid

        from soferai import SoferAI

        client = SoferAI(
            api_key="YOUR_API_KEY",
        )
        client.transformations.generate_summary(
            transcription_id_=uuid.UUID(
                "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
            ),
            transcription_id=uuid.UUID(
                "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
            ),
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v1/transformations/{jsonable_encoder(transcription_id_)}/summary",
            method="POST",
            json={
                "transcription_id": transcription_id,
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    TranscriptSummaryResponse,
                    parse_obj_as(
                        type_=TranscriptSummaryResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 404:
                raise TranscriptionNotFound()
            if _response.status_code == 401:
                raise AuthenticationError()
            _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 get_summary(
        self, transcription_id: uuid.UUID, *, request_options: typing.Optional[RequestOptions] = None
    ) -> TranscriptSummaryResponse:
        """
        Get the Markdown summary for a transcription if it exists.

        Parameters
        ----------
        transcription_id : uuid.UUID
            ID of the transcription to fetch summary for

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

        Returns
        -------
        TranscriptSummaryResponse

        Examples
        --------
        import uuid

        from soferai import SoferAI

        client = SoferAI(
            api_key="YOUR_API_KEY",
        )
        client.transformations.get_summary(
            transcription_id=uuid.UUID(
                "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
            ),
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v1/transformations/{jsonable_encoder(transcription_id)}/summary",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    TranscriptSummaryResponse,
                    parse_obj_as(
                        type_=TranscriptSummaryResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 404:
                raise TranscriptionNotFound()
            if _response.status_code == 401:
                raise AuthenticationError()
            _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 AsyncTransformationsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._client_wrapper = client_wrapper

    async def generate_summary(
        self,
        transcription_id_: uuid.UUID,
        *,
        transcription_id: uuid.UUID,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> TranscriptSummaryResponse:
        """
        Generate a Markdown summary for a transcription. If a summary already exists, it is returned.

        Parameters
        ----------
        transcription_id_ : uuid.UUID
            ID of the transcription to summarize

        transcription_id : uuid.UUID
            ID of the transcription to summarize

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

        Returns
        -------
        TranscriptSummaryResponse

        Examples
        --------
        import asyncio
        import uuid

        from soferai import AsyncSoferAI

        client = AsyncSoferAI(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.transformations.generate_summary(
                transcription_id_=uuid.UUID(
                    "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
                ),
                transcription_id=uuid.UUID(
                    "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
                ),
            )


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v1/transformations/{jsonable_encoder(transcription_id_)}/summary",
            method="POST",
            json={
                "transcription_id": transcription_id,
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    TranscriptSummaryResponse,
                    parse_obj_as(
                        type_=TranscriptSummaryResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 404:
                raise TranscriptionNotFound()
            if _response.status_code == 401:
                raise AuthenticationError()
            _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 get_summary(
        self, transcription_id: uuid.UUID, *, request_options: typing.Optional[RequestOptions] = None
    ) -> TranscriptSummaryResponse:
        """
        Get the Markdown summary for a transcription if it exists.

        Parameters
        ----------
        transcription_id : uuid.UUID
            ID of the transcription to fetch summary for

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

        Returns
        -------
        TranscriptSummaryResponse

        Examples
        --------
        import asyncio
        import uuid

        from soferai import AsyncSoferAI

        client = AsyncSoferAI(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.transformations.get_summary(
                transcription_id=uuid.UUID(
                    "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
                ),
            )


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v1/transformations/{jsonable_encoder(transcription_id)}/summary",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    TranscriptSummaryResponse,
                    parse_obj_as(
                        type_=TranscriptSummaryResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 404:
                raise TranscriptionNotFound()
            if _response.status_code == 401:
                raise AuthenticationError()
            _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)
