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

import contextlib
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.serialization import convert_and_respect_annotation_metadata
from ...core.unchecked_base_model import construct_type
from ...types.converted_format_request import ConvertedFormatRequest
from ...types.export import Export
from ...types.lse_annotation_filter_options_request import LseAnnotationFilterOptionsRequest
from ...types.lse_export_create import LseExportCreate
from ...types.lse_task_filter_options_request import LseTaskFilterOptionsRequest
from ...types.serialization_options_request import SerializationOptionsRequest
from ...types.status7bf_enum import Status7BfEnum
from ...types.user_simple_request import UserSimpleRequest
from .types.convert_exports_response import ConvertExportsResponse

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


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

    @contextlib.contextmanager
    def download_sync(
        self,
        id: int,
        *,
        download_all_tasks: typing.Optional[bool] = None,
        download_resources: typing.Optional[bool] = None,
        export_type: typing.Optional[str] = None,
        ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Iterator[HttpResponse[typing.Iterator[bytes]]]:
        """

                This endpoint is deprecated in Enterprise. Use the async export API instead:
                POST /api/projects/{id}/exports/ (see [Create new export](/api#operation/api_projects_exports_create)).

                In Label Studio Enterprise, this endpoint will always return a 404 Not Found response with instructions to use the async export API.

                <i>Note: if you have a large project it's recommended to use
                export snapshots, this easy export endpoint might have timeouts.</i><br/><br>
                Export annotated tasks as a file in a specific format.
                For example, to export JSON annotations for a project to a file called `annotations.json`,
                run the following from the command line:
                ```bash
                curl -X GET http://localhost:8000/api/projects/{id}/export?exportType=JSON -H 'Authorization: Token abc123' --output 'annotations.json'
                ```
                To export all tasks, including skipped tasks and others without annotations, run the following from the command line:
                ```bash
                curl -X GET http://localhost:8000/api/projects/{id}/export?exportType=JSON&download_all_tasks=true -H 'Authorization: Token abc123' --output 'annotations.json'
                ```
                To export specific tasks with IDs of 123 and 345, run the following from the command line:
                ```bash
                curl -X GET 'http://localhost:8000/api/projects/{id}/export?ids[]=123&ids[]=345' -H 'Authorization: Token abc123' --output 'annotations.json'
                ```


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

        download_all_tasks : typing.Optional[bool]
            If true, download all tasks regardless of status. If false, download only annotated tasks.

        download_resources : typing.Optional[bool]
            If true, download all resource files such as images, audio, and others relevant to the tasks.

        export_type : typing.Optional[str]
            Selected export format (JSON by default)

        ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            Specify a list of task IDs to retrieve only the details for those tasks.

        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]]]
            Exported data
        """
        with self._client_wrapper.httpx_client.stream(
            f"api/projects/{jsonable_encoder(id)}/export",
            method="GET",
            params={
                "download_all_tasks": download_all_tasks,
                "download_resources": download_resources,
                "export_type": export_type,
                "ids": ids,
            },
            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 list_formats(
        self, id: int, *, request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[typing.List[str]]:
        """

                This endpoint is deprecated in Enterprise. Use the async export API instead:
                POST /api/projects/{{id}}/exports/ (see [Create new export](/api#operation/api_projects_exports_create)).

                In Label Studio Enterprise, this endpoint will always return a 404 Not Found response with instructions to use the async export API.

                Retrieve the available export formats for the current project by ID.

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

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

        Returns
        -------
        HttpResponse[typing.List[str]]
            Export formats
        """
        _response = self._client_wrapper.httpx_client.request(
            f"api/projects/{jsonable_encoder(id)}/export/formats",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    typing.List[str],
                    construct_type(
                        type_=typing.List[str],  # 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 list(
        self, id: int, *, ordering: typing.Optional[str] = None, request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[typing.List[Export]]:
        """
        Returns a list of exported files for a specific project by ID.

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

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

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

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

        """
        _response = self._client_wrapper.httpx_client.request(
            f"api/projects/{jsonable_encoder(id)}/exports/",
            method="GET",
            params={
                "ordering": ordering,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    typing.List[Export],
                    construct_type(
                        type_=typing.List[Export],  # 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,
        id: int,
        *,
        annotation_filter_options: typing.Optional[LseAnnotationFilterOptionsRequest] = OMIT,
        converted_formats: typing.Optional[typing.Sequence[ConvertedFormatRequest]] = OMIT,
        counters: typing.Optional[typing.Any] = OMIT,
        created_by: typing.Optional[UserSimpleRequest] = OMIT,
        finished_at: typing.Optional[dt.datetime] = OMIT,
        md5: typing.Optional[str] = OMIT,
        serialization_options: typing.Optional[SerializationOptionsRequest] = OMIT,
        status: typing.Optional[Status7BfEnum] = OMIT,
        task_filter_options: typing.Optional[LseTaskFilterOptionsRequest] = OMIT,
        title: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[LseExportCreate]:
        """
        Create a new export request to start a background task and generate an export file for a specific project by ID.

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

        annotation_filter_options : typing.Optional[LseAnnotationFilterOptionsRequest]

        converted_formats : typing.Optional[typing.Sequence[ConvertedFormatRequest]]

        counters : typing.Optional[typing.Any]

        created_by : typing.Optional[UserSimpleRequest]

        finished_at : typing.Optional[dt.datetime]
            Complete or fail time

        md5 : typing.Optional[str]

        serialization_options : typing.Optional[SerializationOptionsRequest]

        status : typing.Optional[Status7BfEnum]

        task_filter_options : typing.Optional[LseTaskFilterOptionsRequest]

        title : typing.Optional[str]

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

        Returns
        -------
        HttpResponse[LseExportCreate]

        """
        _response = self._client_wrapper.httpx_client.request(
            f"api/projects/{jsonable_encoder(id)}/exports/",
            method="POST",
            json={
                "annotation_filter_options": convert_and_respect_annotation_metadata(
                    object_=annotation_filter_options, annotation=LseAnnotationFilterOptionsRequest, direction="write"
                ),
                "converted_formats": convert_and_respect_annotation_metadata(
                    object_=converted_formats, annotation=typing.Sequence[ConvertedFormatRequest], direction="write"
                ),
                "counters": counters,
                "created_by": convert_and_respect_annotation_metadata(
                    object_=created_by, annotation=UserSimpleRequest, direction="write"
                ),
                "finished_at": finished_at,
                "md5": md5,
                "serialization_options": convert_and_respect_annotation_metadata(
                    object_=serialization_options, annotation=SerializationOptionsRequest, direction="write"
                ),
                "status": status,
                "task_filter_options": convert_and_respect_annotation_metadata(
                    object_=task_filter_options, annotation=LseTaskFilterOptionsRequest, direction="write"
                ),
                "title": title,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    LseExportCreate,
                    construct_type(
                        type_=LseExportCreate,  # 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, export_pk: int, *, request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[Export]:
        """
        Retrieve information about an export file by export ID for a specific project.

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

        export_pk : int
            Primary key identifying the export file.

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

        Returns
        -------
        HttpResponse[Export]

        """
        _response = self._client_wrapper.httpx_client.request(
            f"api/projects/{jsonable_encoder(id)}/exports/{jsonable_encoder(export_pk)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    Export,
                    construct_type(
                        type_=Export,  # 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, export_pk: int, *, request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[None]:
        """
        Delete an export file by specified export ID.

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

        export_pk : int
            Primary key identifying the export file.

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

        Returns
        -------
        HttpResponse[None]
        """
        _response = self._client_wrapper.httpx_client.request(
            f"api/projects/{jsonable_encoder(id)}/exports/{jsonable_encoder(export_pk)}",
            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 convert(
        self,
        id: int,
        export_pk: int,
        *,
        export_type: str,
        download_resources: typing.Optional[bool] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[ConvertExportsResponse]:
        """
        Convert export snapshot to selected format

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

        export_pk : int
            Primary key identifying the export file.

        export_type : str
            Export file format.

        download_resources : typing.Optional[bool]
            Download resources in converter.

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

        Returns
        -------
        HttpResponse[ConvertExportsResponse]

        """
        _response = self._client_wrapper.httpx_client.request(
            f"api/projects/{jsonable_encoder(id)}/exports/{jsonable_encoder(export_pk)}/convert",
            method="POST",
            json={
                "download_resources": download_resources,
                "export_type": export_type,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    ConvertExportsResponse,
                    construct_type(
                        type_=ConvertExportsResponse,  # 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 download(
        self,
        id: int,
        export_pk: int,
        *,
        export_type: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Iterator[HttpResponse[typing.Iterator[bytes]]]:
        """

                Download an export file in the specified format for a specific project. Specify the project ID with the `id`
                parameter in the path and the ID of the export file you want to download using the `export_pk` parameter
                in the path.

                Get the `export_pk` from the response of the request to [Create new export](/api#operation/api_projects_exports_create)
                or after [listing export files](/api#operation/api_projects_exports_list).


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

        export_pk : int
            Primary key identifying the export file.

        export_type : typing.Optional[str]
            Selected export format

        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]]]
            Export file
        """
        with self._client_wrapper.httpx_client.stream(
            f"api/projects/{jsonable_encoder(id)}/exports/{jsonable_encoder(export_pk)}/download",
            method="GET",
            params={
                "exportType": export_type,
            },
            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()


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

    @contextlib.asynccontextmanager
    async def download_sync(
        self,
        id: int,
        *,
        download_all_tasks: typing.Optional[bool] = None,
        download_resources: typing.Optional[bool] = None,
        export_type: typing.Optional[str] = None,
        ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.AsyncIterator[AsyncHttpResponse[typing.AsyncIterator[bytes]]]:
        """

                This endpoint is deprecated in Enterprise. Use the async export API instead:
                POST /api/projects/{id}/exports/ (see [Create new export](/api#operation/api_projects_exports_create)).

                In Label Studio Enterprise, this endpoint will always return a 404 Not Found response with instructions to use the async export API.

                <i>Note: if you have a large project it's recommended to use
                export snapshots, this easy export endpoint might have timeouts.</i><br/><br>
                Export annotated tasks as a file in a specific format.
                For example, to export JSON annotations for a project to a file called `annotations.json`,
                run the following from the command line:
                ```bash
                curl -X GET http://localhost:8000/api/projects/{id}/export?exportType=JSON -H 'Authorization: Token abc123' --output 'annotations.json'
                ```
                To export all tasks, including skipped tasks and others without annotations, run the following from the command line:
                ```bash
                curl -X GET http://localhost:8000/api/projects/{id}/export?exportType=JSON&download_all_tasks=true -H 'Authorization: Token abc123' --output 'annotations.json'
                ```
                To export specific tasks with IDs of 123 and 345, run the following from the command line:
                ```bash
                curl -X GET 'http://localhost:8000/api/projects/{id}/export?ids[]=123&ids[]=345' -H 'Authorization: Token abc123' --output 'annotations.json'
                ```


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

        download_all_tasks : typing.Optional[bool]
            If true, download all tasks regardless of status. If false, download only annotated tasks.

        download_resources : typing.Optional[bool]
            If true, download all resource files such as images, audio, and others relevant to the tasks.

        export_type : typing.Optional[str]
            Selected export format (JSON by default)

        ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            Specify a list of task IDs to retrieve only the details for those tasks.

        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]]]
            Exported data
        """
        async with self._client_wrapper.httpx_client.stream(
            f"api/projects/{jsonable_encoder(id)}/export",
            method="GET",
            params={
                "download_all_tasks": download_all_tasks,
                "download_resources": download_resources,
                "export_type": export_type,
                "ids": ids,
            },
            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 list_formats(
        self, id: int, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[typing.List[str]]:
        """

                This endpoint is deprecated in Enterprise. Use the async export API instead:
                POST /api/projects/{{id}}/exports/ (see [Create new export](/api#operation/api_projects_exports_create)).

                In Label Studio Enterprise, this endpoint will always return a 404 Not Found response with instructions to use the async export API.

                Retrieve the available export formats for the current project by ID.

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

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

        Returns
        -------
        AsyncHttpResponse[typing.List[str]]
            Export formats
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"api/projects/{jsonable_encoder(id)}/export/formats",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    typing.List[str],
                    construct_type(
                        type_=typing.List[str],  # 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 list(
        self, id: int, *, ordering: typing.Optional[str] = None, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[typing.List[Export]]:
        """
        Returns a list of exported files for a specific project by ID.

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

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

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

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

        """
        _response = await self._client_wrapper.httpx_client.request(
            f"api/projects/{jsonable_encoder(id)}/exports/",
            method="GET",
            params={
                "ordering": ordering,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    typing.List[Export],
                    construct_type(
                        type_=typing.List[Export],  # 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,
        id: int,
        *,
        annotation_filter_options: typing.Optional[LseAnnotationFilterOptionsRequest] = OMIT,
        converted_formats: typing.Optional[typing.Sequence[ConvertedFormatRequest]] = OMIT,
        counters: typing.Optional[typing.Any] = OMIT,
        created_by: typing.Optional[UserSimpleRequest] = OMIT,
        finished_at: typing.Optional[dt.datetime] = OMIT,
        md5: typing.Optional[str] = OMIT,
        serialization_options: typing.Optional[SerializationOptionsRequest] = OMIT,
        status: typing.Optional[Status7BfEnum] = OMIT,
        task_filter_options: typing.Optional[LseTaskFilterOptionsRequest] = OMIT,
        title: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[LseExportCreate]:
        """
        Create a new export request to start a background task and generate an export file for a specific project by ID.

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

        annotation_filter_options : typing.Optional[LseAnnotationFilterOptionsRequest]

        converted_formats : typing.Optional[typing.Sequence[ConvertedFormatRequest]]

        counters : typing.Optional[typing.Any]

        created_by : typing.Optional[UserSimpleRequest]

        finished_at : typing.Optional[dt.datetime]
            Complete or fail time

        md5 : typing.Optional[str]

        serialization_options : typing.Optional[SerializationOptionsRequest]

        status : typing.Optional[Status7BfEnum]

        task_filter_options : typing.Optional[LseTaskFilterOptionsRequest]

        title : typing.Optional[str]

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

        Returns
        -------
        AsyncHttpResponse[LseExportCreate]

        """
        _response = await self._client_wrapper.httpx_client.request(
            f"api/projects/{jsonable_encoder(id)}/exports/",
            method="POST",
            json={
                "annotation_filter_options": convert_and_respect_annotation_metadata(
                    object_=annotation_filter_options, annotation=LseAnnotationFilterOptionsRequest, direction="write"
                ),
                "converted_formats": convert_and_respect_annotation_metadata(
                    object_=converted_formats, annotation=typing.Sequence[ConvertedFormatRequest], direction="write"
                ),
                "counters": counters,
                "created_by": convert_and_respect_annotation_metadata(
                    object_=created_by, annotation=UserSimpleRequest, direction="write"
                ),
                "finished_at": finished_at,
                "md5": md5,
                "serialization_options": convert_and_respect_annotation_metadata(
                    object_=serialization_options, annotation=SerializationOptionsRequest, direction="write"
                ),
                "status": status,
                "task_filter_options": convert_and_respect_annotation_metadata(
                    object_=task_filter_options, annotation=LseTaskFilterOptionsRequest, direction="write"
                ),
                "title": title,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    LseExportCreate,
                    construct_type(
                        type_=LseExportCreate,  # 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, export_pk: int, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[Export]:
        """
        Retrieve information about an export file by export ID for a specific project.

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

        export_pk : int
            Primary key identifying the export file.

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

        Returns
        -------
        AsyncHttpResponse[Export]

        """
        _response = await self._client_wrapper.httpx_client.request(
            f"api/projects/{jsonable_encoder(id)}/exports/{jsonable_encoder(export_pk)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    Export,
                    construct_type(
                        type_=Export,  # 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, export_pk: int, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[None]:
        """
        Delete an export file by specified export ID.

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

        export_pk : int
            Primary key identifying the export file.

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

        Returns
        -------
        AsyncHttpResponse[None]
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"api/projects/{jsonable_encoder(id)}/exports/{jsonable_encoder(export_pk)}",
            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 convert(
        self,
        id: int,
        export_pk: int,
        *,
        export_type: str,
        download_resources: typing.Optional[bool] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[ConvertExportsResponse]:
        """
        Convert export snapshot to selected format

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

        export_pk : int
            Primary key identifying the export file.

        export_type : str
            Export file format.

        download_resources : typing.Optional[bool]
            Download resources in converter.

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

        Returns
        -------
        AsyncHttpResponse[ConvertExportsResponse]

        """
        _response = await self._client_wrapper.httpx_client.request(
            f"api/projects/{jsonable_encoder(id)}/exports/{jsonable_encoder(export_pk)}/convert",
            method="POST",
            json={
                "download_resources": download_resources,
                "export_type": export_type,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    ConvertExportsResponse,
                    construct_type(
                        type_=ConvertExportsResponse,  # 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 download(
        self,
        id: int,
        export_pk: int,
        *,
        export_type: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.AsyncIterator[AsyncHttpResponse[typing.AsyncIterator[bytes]]]:
        """

                Download an export file in the specified format for a specific project. Specify the project ID with the `id`
                parameter in the path and the ID of the export file you want to download using the `export_pk` parameter
                in the path.

                Get the `export_pk` from the response of the request to [Create new export](/api#operation/api_projects_exports_create)
                or after [listing export files](/api#operation/api_projects_exports_list).


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

        export_pk : int
            Primary key identifying the export file.

        export_type : typing.Optional[str]
            Selected export format

        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]]]
            Export file
        """
        async with self._client_wrapper.httpx_client.stream(
            f"api/projects/{jsonable_encoder(id)}/exports/{jsonable_encoder(export_pk)}/download",
            method="GET",
            params={
                "exportType": export_type,
            },
            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()
