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

import contextlib
import typing
from json.decoder import JSONDecodeError

from ..core.api_error import ApiError
from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.http_response import AsyncHttpResponse, HttpResponse
from ..core.jsonable_encoder import jsonable_encoder
from ..core.request_options import RequestOptions
from ..core.unchecked_base_model import construct_type
from ..types.maybe_expanded_comment import MaybeExpandedComment

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


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

    def list(
        self,
        *,
        annotation: typing.Optional[int] = None,
        annotators: typing.Optional[str] = None,
        draft: typing.Optional[int] = None,
        expand_created_by: typing.Optional[bool] = None,
        ordering: typing.Optional[str] = None,
        projects: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[typing.List[MaybeExpandedComment]]:
        """
        <Card href="https://humansignal.com/goenterprise">
                <img style="pointer-events: none; margin-left: 0px; margin-right: 0px;" src="https://docs.humansignal.com/images/badge.svg" alt="Label Studio Enterprise badge"/>
                <p style="margin-top: 10px; font-size: 14px;">
                    This endpoint is not available in Label Studio Community Edition. [Learn more about Label Studio Enterprise](https://humansignal.com/goenterprise)
                </p>
            </Card>
        List all comments for a specific annotation ID.

        Parameters
        ----------
        annotation : typing.Optional[int]

        annotators : typing.Optional[str]

        draft : typing.Optional[int]

        expand_created_by : typing.Optional[bool]

        ordering : typing.Optional[str]
            Which field to use when ordering the results.

        projects : typing.Optional[str]

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

        Returns
        -------
        HttpResponse[typing.List[MaybeExpandedComment]]
            List of comments
        """
        _response = self._client_wrapper.httpx_client.request(
            "api/comments/",
            method="GET",
            params={
                "annotation": annotation,
                "annotators": annotators,
                "draft": draft,
                "expand_created_by": expand_created_by,
                "ordering": ordering,
                "projects": projects,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    typing.List[MaybeExpandedComment],
                    construct_type(
                        type_=typing.List[MaybeExpandedComment],  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def create(
        self,
        *,
        expand_created_by: typing.Optional[bool] = None,
        annotation: typing.Optional[int] = OMIT,
        classifications: typing.Optional[typing.Any] = OMIT,
        draft: typing.Optional[int] = OMIT,
        is_resolved: typing.Optional[bool] = OMIT,
        region_ref: typing.Optional[typing.Any] = OMIT,
        text: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[MaybeExpandedComment]:
        """
        <Card href="https://humansignal.com/goenterprise">
                <img style="pointer-events: none; margin-left: 0px; margin-right: 0px;" src="https://docs.humansignal.com/images/badge.svg" alt="Label Studio Enterprise badge"/>
                <p style="margin-top: 10px; font-size: 14px;">
                    This endpoint is not available in Label Studio Community Edition. [Learn more about Label Studio Enterprise](https://humansignal.com/goenterprise)
                </p>
            </Card>
        Create a comment for a specific annotation ID.

        Parameters
        ----------
        expand_created_by : typing.Optional[bool]
            Expand the created_by field

        annotation : typing.Optional[int]

        classifications : typing.Optional[typing.Any]
            Classifications applied by a reviewer or annotator

        draft : typing.Optional[int]

        is_resolved : typing.Optional[bool]
            True if the comment is resolved

        region_ref : typing.Optional[typing.Any]
            Set if this comment is related to a specific part of the annotation. Normally contains region ID and control name.

        text : typing.Optional[str]
            Reviewer or annotator comment

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

        Returns
        -------
        HttpResponse[MaybeExpandedComment]

        """
        _response = self._client_wrapper.httpx_client.request(
            "api/comments/",
            method="POST",
            params={
                "expand_created_by": expand_created_by,
            },
            json={
                "annotation": annotation,
                "classifications": classifications,
                "draft": draft,
                "is_resolved": is_resolved,
                "region_ref": region_ref,
                "text": text,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    MaybeExpandedComment,
                    construct_type(
                        type_=MaybeExpandedComment,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    @contextlib.contextmanager
    def export(
        self,
        *,
        annotation: typing.Optional[int] = None,
        annotators: typing.Optional[str] = None,
        draft: typing.Optional[int] = None,
        expand_created_by: typing.Optional[bool] = None,
        projects: typing.Optional[str] = None,
        tz: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Iterator[HttpResponse[typing.Iterator[bytes]]]:
        """
        <Card href="https://humansignal.com/goenterprise">
                <img style="pointer-events: none; margin-left: 0px; margin-right: 0px;" src="https://docs.humansignal.com/images/badge.svg" alt="Label Studio Enterprise badge"/>
                <p style="margin-top: 10px; font-size: 14px;">
                    This endpoint is not available in Label Studio Community Edition. [Learn more about Label Studio Enterprise](https://humansignal.com/goenterprise)
                </p>
            </Card>
        Export comments to CSV file

        Parameters
        ----------
        annotation : typing.Optional[int]

        annotators : typing.Optional[str]

        draft : typing.Optional[int]

        expand_created_by : typing.Optional[bool]

        projects : typing.Optional[str]

        tz : typing.Optional[str]
            Timezone in which to export the data. Format IANA timezone name, e.g. "America/New_York"

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration. You can pass in configuration such as `chunk_size`, and more to customize the request and response.

        Returns
        -------
        typing.Iterator[HttpResponse[typing.Iterator[bytes]]]
            CSV file with comments
        """
        with self._client_wrapper.httpx_client.stream(
            "api/comments/export/",
            method="GET",
            params={
                "annotation": annotation,
                "annotators": annotators,
                "draft": draft,
                "expand_created_by": expand_created_by,
                "projects": projects,
                "tz": tz,
            },
            request_options=request_options,
        ) as _response:

            def _stream() -> HttpResponse[typing.Iterator[bytes]]:
                try:
                    if 200 <= _response.status_code < 300:
                        _chunk_size = request_options.get("chunk_size", None) if request_options is not None else None
                        return HttpResponse(
                            response=_response, data=(_chunk for _chunk in _response.iter_bytes(chunk_size=_chunk_size))
                        )
                    _response.read()
                    _response_json = _response.json()
                except JSONDecodeError:
                    raise ApiError(
                        status_code=_response.status_code, headers=dict(_response.headers), body=_response.text
                    )
                raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

            yield _stream()

    def get(
        self,
        id: str,
        *,
        expand_created_by: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[MaybeExpandedComment]:
        """
        <Card href="https://humansignal.com/goenterprise">
                <img style="pointer-events: none; margin-left: 0px; margin-right: 0px;" src="https://docs.humansignal.com/images/badge.svg" alt="Label Studio Enterprise badge"/>
                <p style="margin-top: 10px; font-size: 14px;">
                    This endpoint is not available in Label Studio Community Edition. [Learn more about Label Studio Enterprise](https://humansignal.com/goenterprise)
                </p>
            </Card>
        Retrieve a specific comment by ID for an annotation.

        Parameters
        ----------
        id : str

        expand_created_by : typing.Optional[bool]
            Expand the created_by field

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

        Returns
        -------
        HttpResponse[MaybeExpandedComment]

        """
        _response = self._client_wrapper.httpx_client.request(
            f"api/comments/{jsonable_encoder(id)}/",
            method="GET",
            params={
                "expand_created_by": expand_created_by,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    MaybeExpandedComment,
                    construct_type(
                        type_=MaybeExpandedComment,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def delete(
        self,
        id: str,
        *,
        expand_created_by: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[None]:
        """
        <Card href="https://humansignal.com/goenterprise">
                <img style="pointer-events: none; margin-left: 0px; margin-right: 0px;" src="https://docs.humansignal.com/images/badge.svg" alt="Label Studio Enterprise badge"/>
                <p style="margin-top: 10px; font-size: 14px;">
                    This endpoint is not available in Label Studio Community Edition. [Learn more about Label Studio Enterprise](https://humansignal.com/goenterprise)
                </p>
            </Card>
        Delete a comment by ID

        Parameters
        ----------
        id : str

        expand_created_by : typing.Optional[bool]
            Expand the created_by field

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

        Returns
        -------
        HttpResponse[None]
        """
        _response = self._client_wrapper.httpx_client.request(
            f"api/comments/{jsonable_encoder(id)}/",
            method="DELETE",
            params={
                "expand_created_by": expand_created_by,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return HttpResponse(response=_response, data=None)
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def update(
        self,
        id: str,
        *,
        expand_created_by: typing.Optional[bool] = None,
        annotation: typing.Optional[int] = OMIT,
        classifications: typing.Optional[typing.Any] = OMIT,
        draft: typing.Optional[int] = OMIT,
        is_resolved: typing.Optional[bool] = OMIT,
        region_ref: typing.Optional[typing.Any] = OMIT,
        text: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[MaybeExpandedComment]:
        """
        <Card href="https://humansignal.com/goenterprise">
                <img style="pointer-events: none; margin-left: 0px; margin-right: 0px;" src="https://docs.humansignal.com/images/badge.svg" alt="Label Studio Enterprise badge"/>
                <p style="margin-top: 10px; font-size: 14px;">
                    This endpoint is not available in Label Studio Community Edition. [Learn more about Label Studio Enterprise](https://humansignal.com/goenterprise)
                </p>
            </Card>
        Update a specific comment by ID.

        Parameters
        ----------
        id : str

        expand_created_by : typing.Optional[bool]
            Expand the created_by field

        annotation : typing.Optional[int]

        classifications : typing.Optional[typing.Any]
            Classifications applied by a reviewer or annotator

        draft : typing.Optional[int]

        is_resolved : typing.Optional[bool]
            True if the comment is resolved

        region_ref : typing.Optional[typing.Any]
            Set if this comment is related to a specific part of the annotation. Normally contains region ID and control name.

        text : typing.Optional[str]
            Reviewer or annotator comment

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

        Returns
        -------
        HttpResponse[MaybeExpandedComment]

        """
        _response = self._client_wrapper.httpx_client.request(
            f"api/comments/{jsonable_encoder(id)}/",
            method="PATCH",
            params={
                "expand_created_by": expand_created_by,
            },
            json={
                "annotation": annotation,
                "classifications": classifications,
                "draft": draft,
                "is_resolved": is_resolved,
                "region_ref": region_ref,
                "text": text,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    MaybeExpandedComment,
                    construct_type(
                        type_=MaybeExpandedComment,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)


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

    async def list(
        self,
        *,
        annotation: typing.Optional[int] = None,
        annotators: typing.Optional[str] = None,
        draft: typing.Optional[int] = None,
        expand_created_by: typing.Optional[bool] = None,
        ordering: typing.Optional[str] = None,
        projects: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[typing.List[MaybeExpandedComment]]:
        """
        <Card href="https://humansignal.com/goenterprise">
                <img style="pointer-events: none; margin-left: 0px; margin-right: 0px;" src="https://docs.humansignal.com/images/badge.svg" alt="Label Studio Enterprise badge"/>
                <p style="margin-top: 10px; font-size: 14px;">
                    This endpoint is not available in Label Studio Community Edition. [Learn more about Label Studio Enterprise](https://humansignal.com/goenterprise)
                </p>
            </Card>
        List all comments for a specific annotation ID.

        Parameters
        ----------
        annotation : typing.Optional[int]

        annotators : typing.Optional[str]

        draft : typing.Optional[int]

        expand_created_by : typing.Optional[bool]

        ordering : typing.Optional[str]
            Which field to use when ordering the results.

        projects : typing.Optional[str]

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

        Returns
        -------
        AsyncHttpResponse[typing.List[MaybeExpandedComment]]
            List of comments
        """
        _response = await self._client_wrapper.httpx_client.request(
            "api/comments/",
            method="GET",
            params={
                "annotation": annotation,
                "annotators": annotators,
                "draft": draft,
                "expand_created_by": expand_created_by,
                "ordering": ordering,
                "projects": projects,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    typing.List[MaybeExpandedComment],
                    construct_type(
                        type_=typing.List[MaybeExpandedComment],  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def create(
        self,
        *,
        expand_created_by: typing.Optional[bool] = None,
        annotation: typing.Optional[int] = OMIT,
        classifications: typing.Optional[typing.Any] = OMIT,
        draft: typing.Optional[int] = OMIT,
        is_resolved: typing.Optional[bool] = OMIT,
        region_ref: typing.Optional[typing.Any] = OMIT,
        text: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[MaybeExpandedComment]:
        """
        <Card href="https://humansignal.com/goenterprise">
                <img style="pointer-events: none; margin-left: 0px; margin-right: 0px;" src="https://docs.humansignal.com/images/badge.svg" alt="Label Studio Enterprise badge"/>
                <p style="margin-top: 10px; font-size: 14px;">
                    This endpoint is not available in Label Studio Community Edition. [Learn more about Label Studio Enterprise](https://humansignal.com/goenterprise)
                </p>
            </Card>
        Create a comment for a specific annotation ID.

        Parameters
        ----------
        expand_created_by : typing.Optional[bool]
            Expand the created_by field

        annotation : typing.Optional[int]

        classifications : typing.Optional[typing.Any]
            Classifications applied by a reviewer or annotator

        draft : typing.Optional[int]

        is_resolved : typing.Optional[bool]
            True if the comment is resolved

        region_ref : typing.Optional[typing.Any]
            Set if this comment is related to a specific part of the annotation. Normally contains region ID and control name.

        text : typing.Optional[str]
            Reviewer or annotator comment

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

        Returns
        -------
        AsyncHttpResponse[MaybeExpandedComment]

        """
        _response = await self._client_wrapper.httpx_client.request(
            "api/comments/",
            method="POST",
            params={
                "expand_created_by": expand_created_by,
            },
            json={
                "annotation": annotation,
                "classifications": classifications,
                "draft": draft,
                "is_resolved": is_resolved,
                "region_ref": region_ref,
                "text": text,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    MaybeExpandedComment,
                    construct_type(
                        type_=MaybeExpandedComment,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    @contextlib.asynccontextmanager
    async def export(
        self,
        *,
        annotation: typing.Optional[int] = None,
        annotators: typing.Optional[str] = None,
        draft: typing.Optional[int] = None,
        expand_created_by: typing.Optional[bool] = None,
        projects: typing.Optional[str] = None,
        tz: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.AsyncIterator[AsyncHttpResponse[typing.AsyncIterator[bytes]]]:
        """
        <Card href="https://humansignal.com/goenterprise">
                <img style="pointer-events: none; margin-left: 0px; margin-right: 0px;" src="https://docs.humansignal.com/images/badge.svg" alt="Label Studio Enterprise badge"/>
                <p style="margin-top: 10px; font-size: 14px;">
                    This endpoint is not available in Label Studio Community Edition. [Learn more about Label Studio Enterprise](https://humansignal.com/goenterprise)
                </p>
            </Card>
        Export comments to CSV file

        Parameters
        ----------
        annotation : typing.Optional[int]

        annotators : typing.Optional[str]

        draft : typing.Optional[int]

        expand_created_by : typing.Optional[bool]

        projects : typing.Optional[str]

        tz : typing.Optional[str]
            Timezone in which to export the data. Format IANA timezone name, e.g. "America/New_York"

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration. You can pass in configuration such as `chunk_size`, and more to customize the request and response.

        Returns
        -------
        typing.AsyncIterator[AsyncHttpResponse[typing.AsyncIterator[bytes]]]
            CSV file with comments
        """
        async with self._client_wrapper.httpx_client.stream(
            "api/comments/export/",
            method="GET",
            params={
                "annotation": annotation,
                "annotators": annotators,
                "draft": draft,
                "expand_created_by": expand_created_by,
                "projects": projects,
                "tz": tz,
            },
            request_options=request_options,
        ) as _response:

            async def _stream() -> AsyncHttpResponse[typing.AsyncIterator[bytes]]:
                try:
                    if 200 <= _response.status_code < 300:
                        _chunk_size = request_options.get("chunk_size", None) if request_options is not None else None
                        return AsyncHttpResponse(
                            response=_response,
                            data=(_chunk async for _chunk in _response.aiter_bytes(chunk_size=_chunk_size)),
                        )
                    await _response.aread()
                    _response_json = _response.json()
                except JSONDecodeError:
                    raise ApiError(
                        status_code=_response.status_code, headers=dict(_response.headers), body=_response.text
                    )
                raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

            yield await _stream()

    async def get(
        self,
        id: str,
        *,
        expand_created_by: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[MaybeExpandedComment]:
        """
        <Card href="https://humansignal.com/goenterprise">
                <img style="pointer-events: none; margin-left: 0px; margin-right: 0px;" src="https://docs.humansignal.com/images/badge.svg" alt="Label Studio Enterprise badge"/>
                <p style="margin-top: 10px; font-size: 14px;">
                    This endpoint is not available in Label Studio Community Edition. [Learn more about Label Studio Enterprise](https://humansignal.com/goenterprise)
                </p>
            </Card>
        Retrieve a specific comment by ID for an annotation.

        Parameters
        ----------
        id : str

        expand_created_by : typing.Optional[bool]
            Expand the created_by field

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

        Returns
        -------
        AsyncHttpResponse[MaybeExpandedComment]

        """
        _response = await self._client_wrapper.httpx_client.request(
            f"api/comments/{jsonable_encoder(id)}/",
            method="GET",
            params={
                "expand_created_by": expand_created_by,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    MaybeExpandedComment,
                    construct_type(
                        type_=MaybeExpandedComment,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def delete(
        self,
        id: str,
        *,
        expand_created_by: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[None]:
        """
        <Card href="https://humansignal.com/goenterprise">
                <img style="pointer-events: none; margin-left: 0px; margin-right: 0px;" src="https://docs.humansignal.com/images/badge.svg" alt="Label Studio Enterprise badge"/>
                <p style="margin-top: 10px; font-size: 14px;">
                    This endpoint is not available in Label Studio Community Edition. [Learn more about Label Studio Enterprise](https://humansignal.com/goenterprise)
                </p>
            </Card>
        Delete a comment by ID

        Parameters
        ----------
        id : str

        expand_created_by : typing.Optional[bool]
            Expand the created_by field

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

        Returns
        -------
        AsyncHttpResponse[None]
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"api/comments/{jsonable_encoder(id)}/",
            method="DELETE",
            params={
                "expand_created_by": expand_created_by,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return AsyncHttpResponse(response=_response, data=None)
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def update(
        self,
        id: str,
        *,
        expand_created_by: typing.Optional[bool] = None,
        annotation: typing.Optional[int] = OMIT,
        classifications: typing.Optional[typing.Any] = OMIT,
        draft: typing.Optional[int] = OMIT,
        is_resolved: typing.Optional[bool] = OMIT,
        region_ref: typing.Optional[typing.Any] = OMIT,
        text: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[MaybeExpandedComment]:
        """
        <Card href="https://humansignal.com/goenterprise">
                <img style="pointer-events: none; margin-left: 0px; margin-right: 0px;" src="https://docs.humansignal.com/images/badge.svg" alt="Label Studio Enterprise badge"/>
                <p style="margin-top: 10px; font-size: 14px;">
                    This endpoint is not available in Label Studio Community Edition. [Learn more about Label Studio Enterprise](https://humansignal.com/goenterprise)
                </p>
            </Card>
        Update a specific comment by ID.

        Parameters
        ----------
        id : str

        expand_created_by : typing.Optional[bool]
            Expand the created_by field

        annotation : typing.Optional[int]

        classifications : typing.Optional[typing.Any]
            Classifications applied by a reviewer or annotator

        draft : typing.Optional[int]

        is_resolved : typing.Optional[bool]
            True if the comment is resolved

        region_ref : typing.Optional[typing.Any]
            Set if this comment is related to a specific part of the annotation. Normally contains region ID and control name.

        text : typing.Optional[str]
            Reviewer or annotator comment

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

        Returns
        -------
        AsyncHttpResponse[MaybeExpandedComment]

        """
        _response = await self._client_wrapper.httpx_client.request(
            f"api/comments/{jsonable_encoder(id)}/",
            method="PATCH",
            params={
                "expand_created_by": expand_created_by,
            },
            json={
                "annotation": annotation,
                "classifications": classifications,
                "draft": draft,
                "is_resolved": is_resolved,
                "region_ref": region_ref,
                "text": text,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    MaybeExpandedComment,
                    construct_type(
                        type_=MaybeExpandedComment,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
