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

import datetime as dt
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.annotation_review import AnnotationReview

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


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

    def list(
        self,
        *,
        annotation: typing.Optional[int] = None,
        annotation_task_project: typing.Optional[int] = None,
        ordering: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[typing.List[AnnotationReview]]:
        """
        <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 reviews for a specific annotation ID. Only allowed for organizations with reviewing features enabled.

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

        annotation_task_project : typing.Optional[int]

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

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

        Returns
        -------
        HttpResponse[typing.List[AnnotationReview]]

        """
        _response = self._client_wrapper.httpx_client.request(
            "api/annotation-reviews/",
            method="GET",
            params={
                "annotation": annotation,
                "annotation__task__project": annotation_task_project,
                "ordering": ordering,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    typing.List[AnnotationReview],
                    construct_type(
                        type_=typing.List[AnnotationReview],  # 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,
        *,
        annotation: int,
        async_postprocess: typing.Optional[bool] = None,
        accepted: typing.Optional[bool] = OMIT,
        comment: typing.Optional[str] = OMIT,
        last_annotation_history: typing.Optional[int] = OMIT,
        remove_from_queue: typing.Optional[bool] = OMIT,
        result: typing.Optional[typing.Any] = OMIT,
        started_at: typing.Optional[dt.datetime] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[AnnotationReview]:
        """
        <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 review for a specific annotation ID. Only allowed for organizations with reviewing features enabled.

        Parameters
        ----------
        annotation : int
            Corresponding annotation

        async_postprocess : typing.Optional[bool]
            Whether to postprocess the review asynchronously.

        accepted : typing.Optional[bool]
            Accepted or rejected (if false) flag

        comment : typing.Optional[str]

        last_annotation_history : typing.Optional[int]

        remove_from_queue : typing.Optional[bool]

        result : typing.Optional[typing.Any]

        started_at : typing.Optional[dt.datetime]

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

        Returns
        -------
        HttpResponse[AnnotationReview]

        """
        _response = self._client_wrapper.httpx_client.request(
            "api/annotation-reviews/",
            method="POST",
            params={
                "async_postprocess": async_postprocess,
            },
            json={
                "accepted": accepted,
                "annotation": annotation,
                "comment": comment,
                "last_annotation_history": last_annotation_history,
                "remove_from_queue": remove_from_queue,
                "result": result,
                "started_at": started_at,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    AnnotationReview,
                    construct_type(
                        type_=AnnotationReview,  # 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 get(
        self, id: int, *, request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[AnnotationReview]:
        """
        <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 review by ID for an annotation. Only allowed for organizations with reviewing features enabled.

        Parameters
        ----------
        id : int
            A unique integer value identifying this annotation review.

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

        Returns
        -------
        HttpResponse[AnnotationReview]

        """
        _response = self._client_wrapper.httpx_client.request(
            f"api/annotation-reviews/{jsonable_encoder(id)}/",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    AnnotationReview,
                    construct_type(
                        type_=AnnotationReview,  # 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: int, *, 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 review by ID. Only allowed for organizations with reviewing features enabled.

        Parameters
        ----------
        id : int
            A unique integer value identifying this annotation review.

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

        Returns
        -------
        HttpResponse[None]
        """
        _response = self._client_wrapper.httpx_client.request(
            f"api/annotation-reviews/{jsonable_encoder(id)}/",
            method="DELETE",
            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: int,
        *,
        accepted: typing.Optional[bool] = OMIT,
        annotation: typing.Optional[int] = OMIT,
        comment: typing.Optional[str] = OMIT,
        last_annotation_history: typing.Optional[int] = OMIT,
        remove_from_queue: typing.Optional[bool] = OMIT,
        result: typing.Optional[typing.Any] = OMIT,
        started_at: typing.Optional[dt.datetime] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[AnnotationReview]:
        """
        <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 review by ID. Only allowed for organizations with reviewing features enabled.

        Parameters
        ----------
        id : int
            A unique integer value identifying this annotation review.

        accepted : typing.Optional[bool]
            Accepted or rejected (if false) flag

        annotation : typing.Optional[int]
            Corresponding annotation

        comment : typing.Optional[str]

        last_annotation_history : typing.Optional[int]

        remove_from_queue : typing.Optional[bool]

        result : typing.Optional[typing.Any]

        started_at : typing.Optional[dt.datetime]

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

        Returns
        -------
        HttpResponse[AnnotationReview]

        """
        _response = self._client_wrapper.httpx_client.request(
            f"api/annotation-reviews/{jsonable_encoder(id)}/",
            method="PATCH",
            json={
                "accepted": accepted,
                "annotation": annotation,
                "comment": comment,
                "last_annotation_history": last_annotation_history,
                "remove_from_queue": remove_from_queue,
                "result": result,
                "started_at": started_at,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    AnnotationReview,
                    construct_type(
                        type_=AnnotationReview,  # 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 AsyncRawAnnotationReviewsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._client_wrapper = client_wrapper

    async def list(
        self,
        *,
        annotation: typing.Optional[int] = None,
        annotation_task_project: typing.Optional[int] = None,
        ordering: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[typing.List[AnnotationReview]]:
        """
        <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 reviews for a specific annotation ID. Only allowed for organizations with reviewing features enabled.

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

        annotation_task_project : typing.Optional[int]

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

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

        Returns
        -------
        AsyncHttpResponse[typing.List[AnnotationReview]]

        """
        _response = await self._client_wrapper.httpx_client.request(
            "api/annotation-reviews/",
            method="GET",
            params={
                "annotation": annotation,
                "annotation__task__project": annotation_task_project,
                "ordering": ordering,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    typing.List[AnnotationReview],
                    construct_type(
                        type_=typing.List[AnnotationReview],  # 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,
        *,
        annotation: int,
        async_postprocess: typing.Optional[bool] = None,
        accepted: typing.Optional[bool] = OMIT,
        comment: typing.Optional[str] = OMIT,
        last_annotation_history: typing.Optional[int] = OMIT,
        remove_from_queue: typing.Optional[bool] = OMIT,
        result: typing.Optional[typing.Any] = OMIT,
        started_at: typing.Optional[dt.datetime] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[AnnotationReview]:
        """
        <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 review for a specific annotation ID. Only allowed for organizations with reviewing features enabled.

        Parameters
        ----------
        annotation : int
            Corresponding annotation

        async_postprocess : typing.Optional[bool]
            Whether to postprocess the review asynchronously.

        accepted : typing.Optional[bool]
            Accepted or rejected (if false) flag

        comment : typing.Optional[str]

        last_annotation_history : typing.Optional[int]

        remove_from_queue : typing.Optional[bool]

        result : typing.Optional[typing.Any]

        started_at : typing.Optional[dt.datetime]

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

        Returns
        -------
        AsyncHttpResponse[AnnotationReview]

        """
        _response = await self._client_wrapper.httpx_client.request(
            "api/annotation-reviews/",
            method="POST",
            params={
                "async_postprocess": async_postprocess,
            },
            json={
                "accepted": accepted,
                "annotation": annotation,
                "comment": comment,
                "last_annotation_history": last_annotation_history,
                "remove_from_queue": remove_from_queue,
                "result": result,
                "started_at": started_at,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    AnnotationReview,
                    construct_type(
                        type_=AnnotationReview,  # 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 get(
        self, id: int, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[AnnotationReview]:
        """
        <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 review by ID for an annotation. Only allowed for organizations with reviewing features enabled.

        Parameters
        ----------
        id : int
            A unique integer value identifying this annotation review.

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

        Returns
        -------
        AsyncHttpResponse[AnnotationReview]

        """
        _response = await self._client_wrapper.httpx_client.request(
            f"api/annotation-reviews/{jsonable_encoder(id)}/",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    AnnotationReview,
                    construct_type(
                        type_=AnnotationReview,  # 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: int, *, 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 review by ID. Only allowed for organizations with reviewing features enabled.

        Parameters
        ----------
        id : int
            A unique integer value identifying this annotation review.

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

        Returns
        -------
        AsyncHttpResponse[None]
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"api/annotation-reviews/{jsonable_encoder(id)}/",
            method="DELETE",
            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: int,
        *,
        accepted: typing.Optional[bool] = OMIT,
        annotation: typing.Optional[int] = OMIT,
        comment: typing.Optional[str] = OMIT,
        last_annotation_history: typing.Optional[int] = OMIT,
        remove_from_queue: typing.Optional[bool] = OMIT,
        result: typing.Optional[typing.Any] = OMIT,
        started_at: typing.Optional[dt.datetime] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[AnnotationReview]:
        """
        <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 review by ID. Only allowed for organizations with reviewing features enabled.

        Parameters
        ----------
        id : int
            A unique integer value identifying this annotation review.

        accepted : typing.Optional[bool]
            Accepted or rejected (if false) flag

        annotation : typing.Optional[int]
            Corresponding annotation

        comment : typing.Optional[str]

        last_annotation_history : typing.Optional[int]

        remove_from_queue : typing.Optional[bool]

        result : typing.Optional[typing.Any]

        started_at : typing.Optional[dt.datetime]

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

        Returns
        -------
        AsyncHttpResponse[AnnotationReview]

        """
        _response = await self._client_wrapper.httpx_client.request(
            f"api/annotation-reviews/{jsonable_encoder(id)}/",
            method="PATCH",
            json={
                "accepted": accepted,
                "annotation": annotation,
                "comment": comment,
                "last_annotation_history": last_annotation_history,
                "remove_from_queue": remove_from_queue,
                "result": result,
                "started_at": started_at,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    AnnotationReview,
                    construct_type(
                        type_=AnnotationReview,  # 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)
