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

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.pagination import AsyncPager, SyncPager
from ..core.request_options import RequestOptions
from ..core.serialization import convert_and_respect_annotation_metadata
from ..core.unchecked_base_model import construct_type
from ..errors.bad_request_error import BadRequestError
from ..errors.conflict_error import ConflictError
from ..errors.forbidden_error import ForbiddenError
from ..errors.not_found_error import NotFoundError
from ..errors.too_many_requests_error import TooManyRequestsError
from ..errors.unauthorized_error import UnauthorizedError
from ..errors.unprocessable_entity_error import UnprocessableEntityError
from ..types.bad_request import BadRequest
from ..types.comment_response import CommentResponse
from ..types.comment_with_includes import CommentWithIncludes
from ..types.comment_with_includes_response import CommentWithIncludesResponse
from ..types.comments_with_includes_response import CommentsWithIncludesResponse
from ..types.conflict import Conflict
from ..types.forbidden import Forbidden
from ..types.include_total_count import IncludeTotalCount
from ..types.not_found import NotFound
from ..types.request_after_opaque_cursor import RequestAfterOpaqueCursor
from ..types.request_page_size import RequestPageSize
from ..types.too_many_requests import TooManyRequests
from ..types.unauthorized import Unauthorized
from ..types.uuid_ import Uuid
from .types.comments_index_request_include import CommentsIndexRequestInclude
from .types.comments_show_request_include import CommentsShowRequestInclude
from .types.create_comment_params_data import CreateCommentParamsData
from .types.update_comment_params_data import UpdateCommentParamsData

# 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 show(
        self,
        account_id: Uuid,
        comment_id: Uuid,
        *,
        timestamp_as_timecode: typing.Optional[bool] = None,
        include: typing.Optional[CommentsShowRequestInclude] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[CommentWithIncludesResponse]:
        """
        Show a single comment on a file. <br>Rate Limits: 100 calls per 1.00 minute(s) per account_user

        Parameters
        ----------
        account_id : Uuid


        comment_id : Uuid


        timestamp_as_timecode : typing.Optional[bool]


        include : typing.Optional[CommentsShowRequestInclude]


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

        Returns
        -------
        HttpResponse[CommentWithIncludesResponse]
            OK
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v4/accounts/{jsonable_encoder(account_id)}/comments/{jsonable_encoder(comment_id)}",
            method="GET",
            params={
                "timestamp_as_timecode": timestamp_as_timecode,
                "include": include,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    CommentWithIncludesResponse,
                    construct_type(
                        type_=CommentWithIncludesResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        BadRequest,
                        construct_type(
                            type_=BadRequest,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Unauthorized,
                        construct_type(
                            type_=Unauthorized,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 403:
                raise ForbiddenError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Forbidden,
                        construct_type(
                            type_=Forbidden,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 404:
                raise NotFoundError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        NotFound,
                        construct_type(
                            type_=NotFound,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 409:
                raise ConflictError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Conflict,
                        construct_type(
                            type_=Conflict,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        construct_type(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 429:
                raise TooManyRequestsError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        TooManyRequests,
                        construct_type(
                            type_=TooManyRequests,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _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, account_id: Uuid, comment_id: Uuid, *, request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[None]:
        """
        Delete comment from an asset. <br>Rate Limits: 60 calls per 1.00 minute(s) per account_user

        Parameters
        ----------
        account_id : Uuid


        comment_id : Uuid


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

        Returns
        -------
        HttpResponse[None]
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v4/accounts/{jsonable_encoder(account_id)}/comments/{jsonable_encoder(comment_id)}",
            method="DELETE",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return HttpResponse(response=_response, data=None)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        BadRequest,
                        construct_type(
                            type_=BadRequest,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Unauthorized,
                        construct_type(
                            type_=Unauthorized,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 403:
                raise ForbiddenError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Forbidden,
                        construct_type(
                            type_=Forbidden,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 404:
                raise NotFoundError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        NotFound,
                        construct_type(
                            type_=NotFound,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 409:
                raise ConflictError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Conflict,
                        construct_type(
                            type_=Conflict,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        construct_type(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 429:
                raise TooManyRequestsError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        TooManyRequests,
                        construct_type(
                            type_=TooManyRequests,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _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,
        account_id: Uuid,
        comment_id: Uuid,
        *,
        data: UpdateCommentParamsData,
        timestamp_as_timecode: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[CommentResponse]:
        """
        Update comment on given asset. <br>Rate Limits: 10 calls per 1.00 minute(s) per account_user

        Parameters
        ----------
        account_id : Uuid


        comment_id : Uuid


        data : UpdateCommentParamsData

        timestamp_as_timecode : typing.Optional[bool]


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

        Returns
        -------
        HttpResponse[CommentResponse]
            OK
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v4/accounts/{jsonable_encoder(account_id)}/comments/{jsonable_encoder(comment_id)}",
            method="PATCH",
            params={
                "timestamp_as_timecode": timestamp_as_timecode,
            },
            json={
                "data": convert_and_respect_annotation_metadata(
                    object_=data, annotation=UpdateCommentParamsData, direction="write"
                ),
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    CommentResponse,
                    construct_type(
                        type_=CommentResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        BadRequest,
                        construct_type(
                            type_=BadRequest,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Unauthorized,
                        construct_type(
                            type_=Unauthorized,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 403:
                raise ForbiddenError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Forbidden,
                        construct_type(
                            type_=Forbidden,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 404:
                raise NotFoundError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        NotFound,
                        construct_type(
                            type_=NotFound,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 409:
                raise ConflictError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Conflict,
                        construct_type(
                            type_=Conflict,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        construct_type(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 429:
                raise TooManyRequestsError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        TooManyRequests,
                        construct_type(
                            type_=TooManyRequests,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _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 index(
        self,
        account_id: Uuid,
        file_id: Uuid,
        *,
        timestamp_as_timecode: typing.Optional[bool] = None,
        include: typing.Optional[CommentsIndexRequestInclude] = None,
        after: typing.Optional[RequestAfterOpaqueCursor] = None,
        page_size: typing.Optional[RequestPageSize] = None,
        include_total_count: typing.Optional[IncludeTotalCount] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> SyncPager[CommentWithIncludes, CommentsWithIncludesResponse]:
        """
        List comments on a given asset. <br>Rate Limits: 100 calls per 1.00 minute(s) per account_user

        Parameters
        ----------
        account_id : Uuid


        file_id : Uuid


        timestamp_as_timecode : typing.Optional[bool]


        include : typing.Optional[CommentsIndexRequestInclude]


        after : typing.Optional[RequestAfterOpaqueCursor]
            Opaque Cursor query param for requests returning paginated results.
            <br/>
            NOTE: this value is auto-generated and included as part of links from a previous response. It is not intended to be human readable.

        page_size : typing.Optional[RequestPageSize]


        include_total_count : typing.Optional[IncludeTotalCount]


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

        Returns
        -------
        SyncPager[CommentWithIncludes, CommentsWithIncludesResponse]
            OK
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v4/accounts/{jsonable_encoder(account_id)}/files/{jsonable_encoder(file_id)}/comments",
            method="GET",
            params={
                "timestamp_as_timecode": timestamp_as_timecode,
                "include": include,
                "after": after,
                "page_size": page_size,
                "include_total_count": include_total_count,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _parsed_response = typing.cast(
                    CommentsWithIncludesResponse,
                    construct_type(
                        type_=CommentsWithIncludesResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                _items = _parsed_response.data
                _has_next = False
                _get_next = None
                if _parsed_response.links is not None:
                    _parsed_next = _parsed_response.links.next
                    _has_next = _parsed_next is not None and _parsed_next != ""

                    def _fetch_next_page(_next_path):
                        _next_response = self._client_wrapper.httpx_client.request(method="GET", path=_next_path)
                        _next_parsed = typing.cast(
                            CommentsWithIncludesResponse,
                            construct_type(
                                type_=CommentsWithIncludesResponse,  # type: ignore
                                object_=_next_response.json(),
                            ),
                        )
                        _next_items = _next_parsed.data
                        _next_next = _next_parsed.links.next if _next_parsed.links is not None else None
                        _next_has_next = _next_next is not None and _next_next != ""
                        return SyncPager(
                            has_next=_next_has_next,
                            items=_next_items,
                            get_next=(lambda _p=_next_next: _fetch_next_page(_p)) if _next_has_next else None,
                            response=_next_parsed,
                        )

                    _get_next = lambda _p=_parsed_next: _fetch_next_page(_p)
                return SyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        BadRequest,
                        construct_type(
                            type_=BadRequest,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Unauthorized,
                        construct_type(
                            type_=Unauthorized,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 403:
                raise ForbiddenError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Forbidden,
                        construct_type(
                            type_=Forbidden,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 404:
                raise NotFoundError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        NotFound,
                        construct_type(
                            type_=NotFound,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 409:
                raise ConflictError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Conflict,
                        construct_type(
                            type_=Conflict,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        construct_type(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 429:
                raise TooManyRequestsError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        TooManyRequests,
                        construct_type(
                            type_=TooManyRequests,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _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,
        account_id: Uuid,
        file_id: Uuid,
        *,
        data: CreateCommentParamsData,
        timestamp_as_timecode: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[CommentResponse]:
        """
        Create a comment on a file. <br>Rate Limits: 100 calls per 1.00 minute(s) per account_user

        Parameters
        ----------
        account_id : Uuid


        file_id : Uuid


        data : CreateCommentParamsData

        timestamp_as_timecode : typing.Optional[bool]


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

        Returns
        -------
        HttpResponse[CommentResponse]
            Created
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v4/accounts/{jsonable_encoder(account_id)}/files/{jsonable_encoder(file_id)}/comments",
            method="POST",
            params={
                "timestamp_as_timecode": timestamp_as_timecode,
            },
            json={
                "data": convert_and_respect_annotation_metadata(
                    object_=data, annotation=CreateCommentParamsData, direction="write"
                ),
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    CommentResponse,
                    construct_type(
                        type_=CommentResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        BadRequest,
                        construct_type(
                            type_=BadRequest,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Unauthorized,
                        construct_type(
                            type_=Unauthorized,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 403:
                raise ForbiddenError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Forbidden,
                        construct_type(
                            type_=Forbidden,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 404:
                raise NotFoundError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        NotFound,
                        construct_type(
                            type_=NotFound,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 409:
                raise ConflictError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Conflict,
                        construct_type(
                            type_=Conflict,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        construct_type(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 429:
                raise TooManyRequestsError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        TooManyRequests,
                        construct_type(
                            type_=TooManyRequests,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _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 show(
        self,
        account_id: Uuid,
        comment_id: Uuid,
        *,
        timestamp_as_timecode: typing.Optional[bool] = None,
        include: typing.Optional[CommentsShowRequestInclude] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[CommentWithIncludesResponse]:
        """
        Show a single comment on a file. <br>Rate Limits: 100 calls per 1.00 minute(s) per account_user

        Parameters
        ----------
        account_id : Uuid


        comment_id : Uuid


        timestamp_as_timecode : typing.Optional[bool]


        include : typing.Optional[CommentsShowRequestInclude]


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

        Returns
        -------
        AsyncHttpResponse[CommentWithIncludesResponse]
            OK
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v4/accounts/{jsonable_encoder(account_id)}/comments/{jsonable_encoder(comment_id)}",
            method="GET",
            params={
                "timestamp_as_timecode": timestamp_as_timecode,
                "include": include,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    CommentWithIncludesResponse,
                    construct_type(
                        type_=CommentWithIncludesResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        BadRequest,
                        construct_type(
                            type_=BadRequest,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Unauthorized,
                        construct_type(
                            type_=Unauthorized,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 403:
                raise ForbiddenError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Forbidden,
                        construct_type(
                            type_=Forbidden,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 404:
                raise NotFoundError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        NotFound,
                        construct_type(
                            type_=NotFound,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 409:
                raise ConflictError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Conflict,
                        construct_type(
                            type_=Conflict,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        construct_type(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 429:
                raise TooManyRequestsError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        TooManyRequests,
                        construct_type(
                            type_=TooManyRequests,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _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, account_id: Uuid, comment_id: Uuid, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[None]:
        """
        Delete comment from an asset. <br>Rate Limits: 60 calls per 1.00 minute(s) per account_user

        Parameters
        ----------
        account_id : Uuid


        comment_id : Uuid


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

        Returns
        -------
        AsyncHttpResponse[None]
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v4/accounts/{jsonable_encoder(account_id)}/comments/{jsonable_encoder(comment_id)}",
            method="DELETE",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return AsyncHttpResponse(response=_response, data=None)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        BadRequest,
                        construct_type(
                            type_=BadRequest,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Unauthorized,
                        construct_type(
                            type_=Unauthorized,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 403:
                raise ForbiddenError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Forbidden,
                        construct_type(
                            type_=Forbidden,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 404:
                raise NotFoundError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        NotFound,
                        construct_type(
                            type_=NotFound,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 409:
                raise ConflictError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Conflict,
                        construct_type(
                            type_=Conflict,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        construct_type(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 429:
                raise TooManyRequestsError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        TooManyRequests,
                        construct_type(
                            type_=TooManyRequests,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _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,
        account_id: Uuid,
        comment_id: Uuid,
        *,
        data: UpdateCommentParamsData,
        timestamp_as_timecode: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[CommentResponse]:
        """
        Update comment on given asset. <br>Rate Limits: 10 calls per 1.00 minute(s) per account_user

        Parameters
        ----------
        account_id : Uuid


        comment_id : Uuid


        data : UpdateCommentParamsData

        timestamp_as_timecode : typing.Optional[bool]


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

        Returns
        -------
        AsyncHttpResponse[CommentResponse]
            OK
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v4/accounts/{jsonable_encoder(account_id)}/comments/{jsonable_encoder(comment_id)}",
            method="PATCH",
            params={
                "timestamp_as_timecode": timestamp_as_timecode,
            },
            json={
                "data": convert_and_respect_annotation_metadata(
                    object_=data, annotation=UpdateCommentParamsData, direction="write"
                ),
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    CommentResponse,
                    construct_type(
                        type_=CommentResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        BadRequest,
                        construct_type(
                            type_=BadRequest,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Unauthorized,
                        construct_type(
                            type_=Unauthorized,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 403:
                raise ForbiddenError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Forbidden,
                        construct_type(
                            type_=Forbidden,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 404:
                raise NotFoundError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        NotFound,
                        construct_type(
                            type_=NotFound,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 409:
                raise ConflictError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Conflict,
                        construct_type(
                            type_=Conflict,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        construct_type(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 429:
                raise TooManyRequestsError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        TooManyRequests,
                        construct_type(
                            type_=TooManyRequests,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _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 index(
        self,
        account_id: Uuid,
        file_id: Uuid,
        *,
        timestamp_as_timecode: typing.Optional[bool] = None,
        include: typing.Optional[CommentsIndexRequestInclude] = None,
        after: typing.Optional[RequestAfterOpaqueCursor] = None,
        page_size: typing.Optional[RequestPageSize] = None,
        include_total_count: typing.Optional[IncludeTotalCount] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncPager[CommentWithIncludes, CommentsWithIncludesResponse]:
        """
        List comments on a given asset. <br>Rate Limits: 100 calls per 1.00 minute(s) per account_user

        Parameters
        ----------
        account_id : Uuid


        file_id : Uuid


        timestamp_as_timecode : typing.Optional[bool]


        include : typing.Optional[CommentsIndexRequestInclude]


        after : typing.Optional[RequestAfterOpaqueCursor]
            Opaque Cursor query param for requests returning paginated results.
            <br/>
            NOTE: this value is auto-generated and included as part of links from a previous response. It is not intended to be human readable.

        page_size : typing.Optional[RequestPageSize]


        include_total_count : typing.Optional[IncludeTotalCount]


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

        Returns
        -------
        AsyncPager[CommentWithIncludes, CommentsWithIncludesResponse]
            OK
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v4/accounts/{jsonable_encoder(account_id)}/files/{jsonable_encoder(file_id)}/comments",
            method="GET",
            params={
                "timestamp_as_timecode": timestamp_as_timecode,
                "include": include,
                "after": after,
                "page_size": page_size,
                "include_total_count": include_total_count,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _parsed_response = typing.cast(
                    CommentsWithIncludesResponse,
                    construct_type(
                        type_=CommentsWithIncludesResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                _items = _parsed_response.data
                _has_next = False
                _get_next = None
                if _parsed_response.links is not None:
                    _parsed_next = _parsed_response.links.next
                    _has_next = _parsed_next is not None and _parsed_next != ""

                    async def _fetch_next_page(_next_path):
                        _next_response = await self._client_wrapper.httpx_client.request(method="GET", path=_next_path)
                        _next_parsed = typing.cast(
                            CommentsWithIncludesResponse,
                            construct_type(
                                type_=CommentsWithIncludesResponse,  # type: ignore
                                object_=_next_response.json(),
                            ),
                        )
                        _next_items = _next_parsed.data
                        _next_next = _next_parsed.links.next if _next_parsed.links is not None else None
                        _next_has_next = _next_next is not None and _next_next != ""
                        return AsyncPager(
                            has_next=_next_has_next,
                            items=_next_items,
                            get_next=(lambda _p=_next_next: _fetch_next_page(_p)) if _next_has_next else None,
                            response=_next_parsed,
                        )

                    _get_next = lambda _p=_parsed_next: _fetch_next_page(_p)
                return AsyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        BadRequest,
                        construct_type(
                            type_=BadRequest,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Unauthorized,
                        construct_type(
                            type_=Unauthorized,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 403:
                raise ForbiddenError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Forbidden,
                        construct_type(
                            type_=Forbidden,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 404:
                raise NotFoundError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        NotFound,
                        construct_type(
                            type_=NotFound,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 409:
                raise ConflictError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Conflict,
                        construct_type(
                            type_=Conflict,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        construct_type(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 429:
                raise TooManyRequestsError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        TooManyRequests,
                        construct_type(
                            type_=TooManyRequests,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _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,
        account_id: Uuid,
        file_id: Uuid,
        *,
        data: CreateCommentParamsData,
        timestamp_as_timecode: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[CommentResponse]:
        """
        Create a comment on a file. <br>Rate Limits: 100 calls per 1.00 minute(s) per account_user

        Parameters
        ----------
        account_id : Uuid


        file_id : Uuid


        data : CreateCommentParamsData

        timestamp_as_timecode : typing.Optional[bool]


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

        Returns
        -------
        AsyncHttpResponse[CommentResponse]
            Created
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v4/accounts/{jsonable_encoder(account_id)}/files/{jsonable_encoder(file_id)}/comments",
            method="POST",
            params={
                "timestamp_as_timecode": timestamp_as_timecode,
            },
            json={
                "data": convert_and_respect_annotation_metadata(
                    object_=data, annotation=CreateCommentParamsData, direction="write"
                ),
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    CommentResponse,
                    construct_type(
                        type_=CommentResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        BadRequest,
                        construct_type(
                            type_=BadRequest,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Unauthorized,
                        construct_type(
                            type_=Unauthorized,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 403:
                raise ForbiddenError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Forbidden,
                        construct_type(
                            type_=Forbidden,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 404:
                raise NotFoundError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        NotFound,
                        construct_type(
                            type_=NotFound,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 409:
                raise ConflictError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Conflict,
                        construct_type(
                            type_=Conflict,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        construct_type(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 429:
                raise TooManyRequestsError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        TooManyRequests,
                        construct_type(
                            type_=TooManyRequests,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _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)
