"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""

from .basesdk import BaseSDK
from documenso_sdk import models, utils
from documenso_sdk._hooks import HookContext
from documenso_sdk.types import OptionalNullable, UNSET
from documenso_sdk.utils import get_security_from_env
from documenso_sdk.utils.unmarshal_json_response import unmarshal_json_response
from typing import Any, Mapping, Optional, Union


class Envelope(BaseSDK):
    def envelope_find(
        self,
        *,
        query: Optional[str] = None,
        page: Optional[float] = None,
        per_page: Optional[float] = None,
        type_: Optional[models.EnvelopeFindQueryParamType] = None,
        template_id: Optional[float] = None,
        source: Optional[models.EnvelopeFindQueryParamSource] = None,
        status: Optional[models.EnvelopeFindQueryParamStatus] = None,
        folder_id: Optional[str] = None,
        order_by_column: Optional[models.EnvelopeFindOrderByColumn] = None,
        order_by_direction: Optional[
            models.EnvelopeFindOrderByDirection
        ] = models.EnvelopeFindOrderByDirection.DESC,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.EnvelopeFindResponse:
        r"""Find envelopes

        Find envelopes based on search criteria

        :param query: The search query.
        :param page: The pagination page number, starts at 1.
        :param per_page: The number of items per page.
        :param type: Filter envelopes by type (DOCUMENT or TEMPLATE).
        :param template_id: Filter envelopes by the template ID used to create it.
        :param source: Filter envelopes by how it was created.
        :param status: Filter envelopes by the current status.
        :param folder_id: Filter envelopes by folder ID.
        :param order_by_column:
        :param order_by_direction: Sort direction.
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.EnvelopeFindRequest(
            query=query,
            page=page,
            per_page=per_page,
            type=type_,
            template_id=template_id,
            source=source,
            status=status,
            folder_id=folder_id,
            order_by_column=order_by_column,
            order_by_direction=order_by_direction,
        )

        req = self._build_request(
            method="GET",
            path="/envelope",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=False,
            request_has_path_params=False,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = self.do_request(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="envelope-find",
                oauth2_scopes=None,
                security_source=get_security_from_env(
                    self.sdk_configuration.security, models.Security
                ),
            ),
            request=req,
            error_status_codes=["400", "401", "403", "404", "4XX", "500", "5XX"],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return unmarshal_json_response(models.EnvelopeFindResponse, http_res)
        if utils.match_response(http_res, "400", "application/json"):
            response_data = unmarshal_json_response(
                models.EnvelopeFindBadRequestErrorData, http_res
            )
            raise models.EnvelopeFindBadRequestError(response_data, http_res)
        if utils.match_response(http_res, "401", "application/json"):
            response_data = unmarshal_json_response(
                models.EnvelopeFindUnauthorizedErrorData, http_res
            )
            raise models.EnvelopeFindUnauthorizedError(response_data, http_res)
        if utils.match_response(http_res, "403", "application/json"):
            response_data = unmarshal_json_response(
                models.EnvelopeFindForbiddenErrorData, http_res
            )
            raise models.EnvelopeFindForbiddenError(response_data, http_res)
        if utils.match_response(http_res, "404", "application/json"):
            response_data = unmarshal_json_response(
                models.EnvelopeFindNotFoundErrorData, http_res
            )
            raise models.EnvelopeFindNotFoundError(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = unmarshal_json_response(
                models.EnvelopeFindInternalServerErrorData, http_res
            )
            raise models.EnvelopeFindInternalServerError(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise models.APIError("API error occurred", http_res, http_res_text)
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise models.APIError("API error occurred", http_res, http_res_text)

        raise models.APIError("Unexpected response received", http_res)

    async def envelope_find_async(
        self,
        *,
        query: Optional[str] = None,
        page: Optional[float] = None,
        per_page: Optional[float] = None,
        type_: Optional[models.EnvelopeFindQueryParamType] = None,
        template_id: Optional[float] = None,
        source: Optional[models.EnvelopeFindQueryParamSource] = None,
        status: Optional[models.EnvelopeFindQueryParamStatus] = None,
        folder_id: Optional[str] = None,
        order_by_column: Optional[models.EnvelopeFindOrderByColumn] = None,
        order_by_direction: Optional[
            models.EnvelopeFindOrderByDirection
        ] = models.EnvelopeFindOrderByDirection.DESC,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.EnvelopeFindResponse:
        r"""Find envelopes

        Find envelopes based on search criteria

        :param query: The search query.
        :param page: The pagination page number, starts at 1.
        :param per_page: The number of items per page.
        :param type: Filter envelopes by type (DOCUMENT or TEMPLATE).
        :param template_id: Filter envelopes by the template ID used to create it.
        :param source: Filter envelopes by how it was created.
        :param status: Filter envelopes by the current status.
        :param folder_id: Filter envelopes by folder ID.
        :param order_by_column:
        :param order_by_direction: Sort direction.
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.EnvelopeFindRequest(
            query=query,
            page=page,
            per_page=per_page,
            type=type_,
            template_id=template_id,
            source=source,
            status=status,
            folder_id=folder_id,
            order_by_column=order_by_column,
            order_by_direction=order_by_direction,
        )

        req = self._build_request_async(
            method="GET",
            path="/envelope",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=False,
            request_has_path_params=False,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = await self.do_request_async(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="envelope-find",
                oauth2_scopes=None,
                security_source=get_security_from_env(
                    self.sdk_configuration.security, models.Security
                ),
            ),
            request=req,
            error_status_codes=["400", "401", "403", "404", "4XX", "500", "5XX"],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return unmarshal_json_response(models.EnvelopeFindResponse, http_res)
        if utils.match_response(http_res, "400", "application/json"):
            response_data = unmarshal_json_response(
                models.EnvelopeFindBadRequestErrorData, http_res
            )
            raise models.EnvelopeFindBadRequestError(response_data, http_res)
        if utils.match_response(http_res, "401", "application/json"):
            response_data = unmarshal_json_response(
                models.EnvelopeFindUnauthorizedErrorData, http_res
            )
            raise models.EnvelopeFindUnauthorizedError(response_data, http_res)
        if utils.match_response(http_res, "403", "application/json"):
            response_data = unmarshal_json_response(
                models.EnvelopeFindForbiddenErrorData, http_res
            )
            raise models.EnvelopeFindForbiddenError(response_data, http_res)
        if utils.match_response(http_res, "404", "application/json"):
            response_data = unmarshal_json_response(
                models.EnvelopeFindNotFoundErrorData, http_res
            )
            raise models.EnvelopeFindNotFoundError(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = unmarshal_json_response(
                models.EnvelopeFindInternalServerErrorData, http_res
            )
            raise models.EnvelopeFindInternalServerError(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise models.APIError("API error occurred", http_res, http_res_text)
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise models.APIError("API error occurred", http_res, http_res_text)

        raise models.APIError("Unexpected response received", http_res)

    def envelope_audit_log_find(
        self,
        *,
        envelope_id: str,
        page: Optional[float] = None,
        per_page: Optional[float] = None,
        order_by_column: Optional[models.EnvelopeAuditLogFindOrderByColumn] = None,
        order_by_direction: Optional[
            models.EnvelopeAuditLogFindOrderByDirection
        ] = None,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.EnvelopeAuditLogFindResponse:
        r"""Get envelope audit logs

        Find audit logs based on a search criteria

        :param envelope_id: Envelope ID
        :param page: The pagination page number, starts at 1.
        :param per_page: The number of items per page.
        :param order_by_column:
        :param order_by_direction:
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.EnvelopeAuditLogFindRequest(
            envelope_id=envelope_id,
            page=page,
            per_page=per_page,
            order_by_column=order_by_column,
            order_by_direction=order_by_direction,
        )

        req = self._build_request(
            method="GET",
            path="/envelope/{envelopeId}/audit-log",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=False,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = self.do_request(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="envelope-auditLog-find",
                oauth2_scopes=None,
                security_source=get_security_from_env(
                    self.sdk_configuration.security, models.Security
                ),
            ),
            request=req,
            error_status_codes=["400", "401", "403", "404", "4XX", "500", "5XX"],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return unmarshal_json_response(
                models.EnvelopeAuditLogFindResponse, http_res
            )
        if utils.match_response(http_res, "400", "application/json"):
            response_data = unmarshal_json_response(
                models.EnvelopeAuditLogFindBadRequestErrorData, http_res
            )
            raise models.EnvelopeAuditLogFindBadRequestError(response_data, http_res)
        if utils.match_response(http_res, "401", "application/json"):
            response_data = unmarshal_json_response(
                models.EnvelopeAuditLogFindUnauthorizedErrorData, http_res
            )
            raise models.EnvelopeAuditLogFindUnauthorizedError(response_data, http_res)
        if utils.match_response(http_res, "403", "application/json"):
            response_data = unmarshal_json_response(
                models.EnvelopeAuditLogFindForbiddenErrorData, http_res
            )
            raise models.EnvelopeAuditLogFindForbiddenError(response_data, http_res)
        if utils.match_response(http_res, "404", "application/json"):
            response_data = unmarshal_json_response(
                models.EnvelopeAuditLogFindNotFoundErrorData, http_res
            )
            raise models.EnvelopeAuditLogFindNotFoundError(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = unmarshal_json_response(
                models.EnvelopeAuditLogFindInternalServerErrorData, http_res
            )
            raise models.EnvelopeAuditLogFindInternalServerError(
                response_data, http_res
            )
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise models.APIError("API error occurred", http_res, http_res_text)
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise models.APIError("API error occurred", http_res, http_res_text)

        raise models.APIError("Unexpected response received", http_res)

    async def envelope_audit_log_find_async(
        self,
        *,
        envelope_id: str,
        page: Optional[float] = None,
        per_page: Optional[float] = None,
        order_by_column: Optional[models.EnvelopeAuditLogFindOrderByColumn] = None,
        order_by_direction: Optional[
            models.EnvelopeAuditLogFindOrderByDirection
        ] = None,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.EnvelopeAuditLogFindResponse:
        r"""Get envelope audit logs

        Find audit logs based on a search criteria

        :param envelope_id: Envelope ID
        :param page: The pagination page number, starts at 1.
        :param per_page: The number of items per page.
        :param order_by_column:
        :param order_by_direction:
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.EnvelopeAuditLogFindRequest(
            envelope_id=envelope_id,
            page=page,
            per_page=per_page,
            order_by_column=order_by_column,
            order_by_direction=order_by_direction,
        )

        req = self._build_request_async(
            method="GET",
            path="/envelope/{envelopeId}/audit-log",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=False,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = await self.do_request_async(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="envelope-auditLog-find",
                oauth2_scopes=None,
                security_source=get_security_from_env(
                    self.sdk_configuration.security, models.Security
                ),
            ),
            request=req,
            error_status_codes=["400", "401", "403", "404", "4XX", "500", "5XX"],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return unmarshal_json_response(
                models.EnvelopeAuditLogFindResponse, http_res
            )
        if utils.match_response(http_res, "400", "application/json"):
            response_data = unmarshal_json_response(
                models.EnvelopeAuditLogFindBadRequestErrorData, http_res
            )
            raise models.EnvelopeAuditLogFindBadRequestError(response_data, http_res)
        if utils.match_response(http_res, "401", "application/json"):
            response_data = unmarshal_json_response(
                models.EnvelopeAuditLogFindUnauthorizedErrorData, http_res
            )
            raise models.EnvelopeAuditLogFindUnauthorizedError(response_data, http_res)
        if utils.match_response(http_res, "403", "application/json"):
            response_data = unmarshal_json_response(
                models.EnvelopeAuditLogFindForbiddenErrorData, http_res
            )
            raise models.EnvelopeAuditLogFindForbiddenError(response_data, http_res)
        if utils.match_response(http_res, "404", "application/json"):
            response_data = unmarshal_json_response(
                models.EnvelopeAuditLogFindNotFoundErrorData, http_res
            )
            raise models.EnvelopeAuditLogFindNotFoundError(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = unmarshal_json_response(
                models.EnvelopeAuditLogFindInternalServerErrorData, http_res
            )
            raise models.EnvelopeAuditLogFindInternalServerError(
                response_data, http_res
            )
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise models.APIError("API error occurred", http_res, http_res_text)
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise models.APIError("API error occurred", http_res, http_res_text)

        raise models.APIError("Unexpected response received", http_res)

    def envelope_get_many(
        self,
        *,
        ids: Union[models.Ids, models.IdsTypedDict],
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.EnvelopeGetManyResponse:
        r"""Get multiple envelopes

        Retrieve multiple envelopes by their IDs

        :param ids:
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.EnvelopeGetManyRequest(
            ids=utils.get_pydantic_model(ids, models.Ids),
        )

        req = self._build_request(
            method="POST",
            path="/envelope/get-many",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=True,
            request_has_path_params=False,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            get_serialized_body=lambda: utils.serialize_request_body(
                request, False, False, "json", models.EnvelopeGetManyRequest
            ),
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = self.do_request(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="envelope-getMany",
                oauth2_scopes=None,
                security_source=get_security_from_env(
                    self.sdk_configuration.security, models.Security
                ),
            ),
            request=req,
            error_status_codes=["400", "401", "403", "4XX", "500", "5XX"],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return unmarshal_json_response(models.EnvelopeGetManyResponse, http_res)
        if utils.match_response(http_res, "400", "application/json"):
            response_data = unmarshal_json_response(
                models.EnvelopeGetManyBadRequestErrorData, http_res
            )
            raise models.EnvelopeGetManyBadRequestError(response_data, http_res)
        if utils.match_response(http_res, "401", "application/json"):
            response_data = unmarshal_json_response(
                models.EnvelopeGetManyUnauthorizedErrorData, http_res
            )
            raise models.EnvelopeGetManyUnauthorizedError(response_data, http_res)
        if utils.match_response(http_res, "403", "application/json"):
            response_data = unmarshal_json_response(
                models.EnvelopeGetManyForbiddenErrorData, http_res
            )
            raise models.EnvelopeGetManyForbiddenError(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = unmarshal_json_response(
                models.EnvelopeGetManyInternalServerErrorData, http_res
            )
            raise models.EnvelopeGetManyInternalServerError(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise models.APIError("API error occurred", http_res, http_res_text)
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise models.APIError("API error occurred", http_res, http_res_text)

        raise models.APIError("Unexpected response received", http_res)

    async def envelope_get_many_async(
        self,
        *,
        ids: Union[models.Ids, models.IdsTypedDict],
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.EnvelopeGetManyResponse:
        r"""Get multiple envelopes

        Retrieve multiple envelopes by their IDs

        :param ids:
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.EnvelopeGetManyRequest(
            ids=utils.get_pydantic_model(ids, models.Ids),
        )

        req = self._build_request_async(
            method="POST",
            path="/envelope/get-many",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=True,
            request_has_path_params=False,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            get_serialized_body=lambda: utils.serialize_request_body(
                request, False, False, "json", models.EnvelopeGetManyRequest
            ),
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = await self.do_request_async(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="envelope-getMany",
                oauth2_scopes=None,
                security_source=get_security_from_env(
                    self.sdk_configuration.security, models.Security
                ),
            ),
            request=req,
            error_status_codes=["400", "401", "403", "4XX", "500", "5XX"],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return unmarshal_json_response(models.EnvelopeGetManyResponse, http_res)
        if utils.match_response(http_res, "400", "application/json"):
            response_data = unmarshal_json_response(
                models.EnvelopeGetManyBadRequestErrorData, http_res
            )
            raise models.EnvelopeGetManyBadRequestError(response_data, http_res)
        if utils.match_response(http_res, "401", "application/json"):
            response_data = unmarshal_json_response(
                models.EnvelopeGetManyUnauthorizedErrorData, http_res
            )
            raise models.EnvelopeGetManyUnauthorizedError(response_data, http_res)
        if utils.match_response(http_res, "403", "application/json"):
            response_data = unmarshal_json_response(
                models.EnvelopeGetManyForbiddenErrorData, http_res
            )
            raise models.EnvelopeGetManyForbiddenError(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = unmarshal_json_response(
                models.EnvelopeGetManyInternalServerErrorData, http_res
            )
            raise models.EnvelopeGetManyInternalServerError(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise models.APIError("API error occurred", http_res, http_res_text)
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise models.APIError("API error occurred", http_res, http_res_text)

        raise models.APIError("Unexpected response received", http_res)
