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

import datetime as dt
import typing
import urllib.parse
from json.decoder import JSONDecodeError

from .....core.api_error import ApiError
from .....core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from .....core.datetime_utils import serialize_datetime
from .....core.remove_none_from_dict import remove_none_from_dict
from ....commons.errors.auth_header_malformed_error import AuthHeaderMalformedError
from ....commons.errors.auth_header_missing_error import AuthHeaderMissingError
from ....commons.errors.forbidden import Forbidden
from ....commons.errors.not_found import NotFound
from ....commons.errors.unauthorized import Unauthorized
from ....commons.errors.unimplemented import Unimplemented
from ....commons.types.order_direction import OrderDirection
from ....entity_types.types.entity_id import EntityId
from ....entity_types.types.entity_user_id import EntityUserId
from ....invoice_types.errors.invoice_query_error import InvoiceQueryError
from ....invoice_types.types.find_invoice_response import FindInvoiceResponse
from ....invoice_types.types.invoice_id import InvoiceId
from ....invoice_types.types.invoice_metrics_response import InvoiceMetricsResponse
from ....invoice_types.types.invoice_order_by_field import InvoiceOrderByField
from ....invoice_types.types.invoice_response import InvoiceResponse
from ....invoice_types.types.invoice_status import InvoiceStatus
from ....payment_method_types.types.currency_code import CurrencyCode

try:
    import pydantic.v1 as pydantic  # type: ignore
except ImportError:
    import pydantic  # type: ignore


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

    def find(
        self,
        entity_id: EntityId,
        *,
        exclude_payables: typing.Optional[bool] = None,
        exclude_receivables: typing.Optional[bool] = None,
        start_date: typing.Optional[dt.datetime] = None,
        end_date: typing.Optional[dt.datetime] = None,
        order_by: typing.Optional[InvoiceOrderByField] = None,
        order_direction: typing.Optional[OrderDirection] = None,
        limit: typing.Optional[int] = None,
        starting_after: typing.Optional[InvoiceId] = None,
        search: typing.Optional[str] = None,
        payer_id: typing.Optional[typing.Union[EntityId, typing.List[EntityId]]] = None,
        vendor_id: typing.Optional[typing.Union[EntityId, typing.List[EntityId]]] = None,
        approver_id: typing.Optional[typing.Union[EntityUserId, typing.List[EntityUserId]]] = None,
        invoice_id: typing.Optional[typing.Union[InvoiceId, typing.List[InvoiceId]]] = None,
        status: typing.Optional[typing.Union[InvoiceStatus, typing.List[InvoiceStatus]]] = None,
        include_fees: typing.Optional[bool] = None,
    ) -> FindInvoiceResponse:
        """
        Get invoices for an entity with the given filters.

        Parameters:
            - entity_id: EntityId.

            - exclude_payables: typing.Optional[bool]. Return only invoices that are receivable by the entity.

            - exclude_receivables: typing.Optional[bool]. Return only invoices that are payable by the entity.

            - start_date: typing.Optional[dt.datetime]. Start date for invoice created on date filter.

            - end_date: typing.Optional[dt.datetime]. End date for invoice created date filter.

            - order_by: typing.Optional[InvoiceOrderByField]. Field to order invoices by. Defaults to CREATED_AT.

            - order_direction: typing.Optional[OrderDirection]. Direction to order invoices by. Defaults to asc.

            - limit: typing.Optional[int]. Number of invoices to return. Limit can range between 1 and 100, and the default is 10.

            - starting_after: typing.Optional[InvoiceId]. The ID of the invoice to start after. If not provided, the first page of invoices will be returned.

            - search: typing.Optional[str]. Filter vendors by name. Partial matches are supported.

            - payer_id: typing.Optional[typing.Union[EntityId, typing.List[EntityId]]]. Filter invoices by payer ID.

            - vendor_id: typing.Optional[typing.Union[EntityId, typing.List[EntityId]]]. Filter invoices by vendor ID.

            - approver_id: typing.Optional[typing.Union[EntityUserId, typing.List[EntityUserId]]]. Filter invoices by assigned approver user ID.

            - invoice_id: typing.Optional[typing.Union[InvoiceId, typing.List[InvoiceId]]]. Filter invoices by invoice ID.

            - status: typing.Optional[typing.Union[InvoiceStatus, typing.List[InvoiceStatus]]]. Invoice status to filter on.

            - include_fees: typing.Optional[bool]. If true, will include fees as part of the response.
        """
        _response = self._client_wrapper.httpx_client.request(
            "GET",
            urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"entity/{entity_id}/invoices"),
            params=remove_none_from_dict(
                {
                    "excludePayables": exclude_payables,
                    "excludeReceivables": exclude_receivables,
                    "startDate": serialize_datetime(start_date) if start_date is not None else None,
                    "endDate": serialize_datetime(end_date) if end_date is not None else None,
                    "orderBy": order_by,
                    "orderDirection": order_direction,
                    "limit": limit,
                    "startingAfter": starting_after,
                    "search": search,
                    "payerId": payer_id,
                    "vendorId": vendor_id,
                    "approverId": approver_id,
                    "invoiceId": invoice_id,
                    "status": status,
                    "includeFees": include_fees,
                }
            ),
            headers=self._client_wrapper.get_headers(),
            timeout=60,
        )
        try:
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        if 200 <= _response.status_code < 300:
            return pydantic.parse_obj_as(FindInvoiceResponse, _response_json)  # type: ignore
        if "errorName" in _response_json:
            if _response_json["errorName"] == "InvoiceQueryError":
                raise InvoiceQueryError(pydantic.parse_obj_as(str, _response_json["content"]))  # type: ignore
            if _response_json["errorName"] == "AuthHeaderMissingError":
                raise AuthHeaderMissingError()
            if _response_json["errorName"] == "AuthHeaderMalformedError":
                raise AuthHeaderMalformedError(pydantic.parse_obj_as(str, _response_json["content"]))  # type: ignore
            if _response_json["errorName"] == "Unauthorized":
                raise Unauthorized(pydantic.parse_obj_as(str, _response_json["content"]))  # type: ignore
            if _response_json["errorName"] == "Forbidden":
                raise Forbidden(pydantic.parse_obj_as(str, _response_json["content"]))  # type: ignore
            if _response_json["errorName"] == "NotFound":
                raise NotFound(pydantic.parse_obj_as(str, _response_json["content"]))  # type: ignore
            if _response_json["errorName"] == "Unimplemented":
                raise Unimplemented(pydantic.parse_obj_as(str, _response_json["content"]))  # type: ignore
        raise ApiError(status_code=_response.status_code, body=_response_json)

    def get(
        self, entity_id: EntityId, invoice_id: InvoiceId, *, include_fees: typing.Optional[bool] = None
    ) -> InvoiceResponse:
        """
        Parameters:
            - entity_id: EntityId.

            - invoice_id: InvoiceId. ID of the invoice to retrieve. This can be the full invoice ID (in_11aa2b77-6391-49e4-8c3f-b198009202c1) or the first 8 characters of the ID (11aa2b77).

            - include_fees: typing.Optional[bool]. If true, will include fees as part of the response.
        """
        _response = self._client_wrapper.httpx_client.request(
            "GET",
            urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"entity/{entity_id}/invoice/{invoice_id}"),
            params=remove_none_from_dict({"includeFees": include_fees}),
            headers=self._client_wrapper.get_headers(),
            timeout=60,
        )
        try:
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        if 200 <= _response.status_code < 300:
            return pydantic.parse_obj_as(InvoiceResponse, _response_json)  # type: ignore
        if "errorName" in _response_json:
            if _response_json["errorName"] == "AuthHeaderMissingError":
                raise AuthHeaderMissingError()
            if _response_json["errorName"] == "AuthHeaderMalformedError":
                raise AuthHeaderMalformedError(pydantic.parse_obj_as(str, _response_json["content"]))  # type: ignore
            if _response_json["errorName"] == "Unauthorized":
                raise Unauthorized(pydantic.parse_obj_as(str, _response_json["content"]))  # type: ignore
            if _response_json["errorName"] == "Forbidden":
                raise Forbidden(pydantic.parse_obj_as(str, _response_json["content"]))  # type: ignore
            if _response_json["errorName"] == "NotFound":
                raise NotFound(pydantic.parse_obj_as(str, _response_json["content"]))  # type: ignore
            if _response_json["errorName"] == "Unimplemented":
                raise Unimplemented(pydantic.parse_obj_as(str, _response_json["content"]))  # type: ignore
        raise ApiError(status_code=_response.status_code, body=_response_json)

    def metrics(
        self,
        entity_id: EntityId,
        *,
        search: typing.Optional[str] = None,
        exclude_payables: typing.Optional[bool] = None,
        exclude_receivables: typing.Optional[bool] = None,
        payer_id: typing.Optional[typing.Union[EntityId, typing.List[EntityId]]] = None,
        vendor_id: typing.Optional[typing.Union[EntityId, typing.List[EntityId]]] = None,
        approver_id: typing.Optional[typing.Union[EntityUserId, typing.List[EntityUserId]]] = None,
        invoice_id: typing.Optional[typing.Union[InvoiceId, typing.List[InvoiceId]]] = None,
        status: typing.Optional[typing.Union[InvoiceStatus, typing.List[InvoiceStatus]]] = None,
        due_date_start: typing.Optional[dt.datetime] = None,
        due_date_end: typing.Optional[dt.datetime] = None,
        created_date_start: typing.Optional[dt.datetime] = None,
        created_date_end: typing.Optional[dt.datetime] = None,
        currency: typing.Optional[typing.Union[CurrencyCode, typing.List[CurrencyCode]]] = None,
    ) -> typing.List[InvoiceMetricsResponse]:
        """
        Get invoice metrics for an entity with the given filters.

        Parameters:
            - entity_id: EntityId.

            - search: typing.Optional[str]. Filter vendors by name. Partial matches are supported.

            - exclude_payables: typing.Optional[bool]. Only return invoices that are not payable by the entity. This will return only invoices that are receivable by the entity.

            - exclude_receivables: typing.Optional[bool]. Only return invoices that are not receivable by the entity. This will return only invoices that are payable by the entity.

            - payer_id: typing.Optional[typing.Union[EntityId, typing.List[EntityId]]]. Filter invoices by payer ID.

            - vendor_id: typing.Optional[typing.Union[EntityId, typing.List[EntityId]]]. Filter invoices by vendor ID.

            - approver_id: typing.Optional[typing.Union[EntityUserId, typing.List[EntityUserId]]]. Filter invoices by assigned approver user ID.

            - invoice_id: typing.Optional[typing.Union[InvoiceId, typing.List[InvoiceId]]]. Filter invoices by invoice ID.

            - status: typing.Optional[typing.Union[InvoiceStatus, typing.List[InvoiceStatus]]]. Invoice status to filter on

            - due_date_start: typing.Optional[dt.datetime]. Start date for invoice dueDate filter.

            - due_date_end: typing.Optional[dt.datetime]. End date for invoice dueDate filter.

            - created_date_start: typing.Optional[dt.datetime]. Start date for invoice created on date filter.

            - created_date_end: typing.Optional[dt.datetime]. End date for invoice created date filter.

            - currency: typing.Optional[typing.Union[CurrencyCode, typing.List[CurrencyCode]]]. Currency to filter on
        """
        _response = self._client_wrapper.httpx_client.request(
            "GET",
            urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"entity/{entity_id}/invoice-metrics"),
            params=remove_none_from_dict(
                {
                    "search": search,
                    "excludePayables": exclude_payables,
                    "excludeReceivables": exclude_receivables,
                    "payerId": payer_id,
                    "vendorId": vendor_id,
                    "approverId": approver_id,
                    "invoiceId": invoice_id,
                    "status": status,
                    "dueDateStart": serialize_datetime(due_date_start) if due_date_start is not None else None,
                    "dueDateEnd": serialize_datetime(due_date_end) if due_date_end is not None else None,
                    "createdDateStart": serialize_datetime(created_date_start)
                    if created_date_start is not None
                    else None,
                    "createdDateEnd": serialize_datetime(created_date_end) if created_date_end is not None else None,
                    "currency": currency,
                }
            ),
            headers=self._client_wrapper.get_headers(),
            timeout=60,
        )
        try:
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        if 200 <= _response.status_code < 300:
            return pydantic.parse_obj_as(typing.List[InvoiceMetricsResponse], _response_json)  # type: ignore
        if "errorName" in _response_json:
            if _response_json["errorName"] == "InvoiceQueryError":
                raise InvoiceQueryError(pydantic.parse_obj_as(str, _response_json["content"]))  # type: ignore
            if _response_json["errorName"] == "AuthHeaderMissingError":
                raise AuthHeaderMissingError()
            if _response_json["errorName"] == "AuthHeaderMalformedError":
                raise AuthHeaderMalformedError(pydantic.parse_obj_as(str, _response_json["content"]))  # type: ignore
            if _response_json["errorName"] == "Unauthorized":
                raise Unauthorized(pydantic.parse_obj_as(str, _response_json["content"]))  # type: ignore
            if _response_json["errorName"] == "Forbidden":
                raise Forbidden(pydantic.parse_obj_as(str, _response_json["content"]))  # type: ignore
            if _response_json["errorName"] == "NotFound":
                raise NotFound(pydantic.parse_obj_as(str, _response_json["content"]))  # type: ignore
            if _response_json["errorName"] == "Unimplemented":
                raise Unimplemented(pydantic.parse_obj_as(str, _response_json["content"]))  # type: ignore
        raise ApiError(status_code=_response.status_code, body=_response_json)


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

    async def find(
        self,
        entity_id: EntityId,
        *,
        exclude_payables: typing.Optional[bool] = None,
        exclude_receivables: typing.Optional[bool] = None,
        start_date: typing.Optional[dt.datetime] = None,
        end_date: typing.Optional[dt.datetime] = None,
        order_by: typing.Optional[InvoiceOrderByField] = None,
        order_direction: typing.Optional[OrderDirection] = None,
        limit: typing.Optional[int] = None,
        starting_after: typing.Optional[InvoiceId] = None,
        search: typing.Optional[str] = None,
        payer_id: typing.Optional[typing.Union[EntityId, typing.List[EntityId]]] = None,
        vendor_id: typing.Optional[typing.Union[EntityId, typing.List[EntityId]]] = None,
        approver_id: typing.Optional[typing.Union[EntityUserId, typing.List[EntityUserId]]] = None,
        invoice_id: typing.Optional[typing.Union[InvoiceId, typing.List[InvoiceId]]] = None,
        status: typing.Optional[typing.Union[InvoiceStatus, typing.List[InvoiceStatus]]] = None,
        include_fees: typing.Optional[bool] = None,
    ) -> FindInvoiceResponse:
        """
        Get invoices for an entity with the given filters.

        Parameters:
            - entity_id: EntityId.

            - exclude_payables: typing.Optional[bool]. Return only invoices that are receivable by the entity.

            - exclude_receivables: typing.Optional[bool]. Return only invoices that are payable by the entity.

            - start_date: typing.Optional[dt.datetime]. Start date for invoice created on date filter.

            - end_date: typing.Optional[dt.datetime]. End date for invoice created date filter.

            - order_by: typing.Optional[InvoiceOrderByField]. Field to order invoices by. Defaults to CREATED_AT.

            - order_direction: typing.Optional[OrderDirection]. Direction to order invoices by. Defaults to asc.

            - limit: typing.Optional[int]. Number of invoices to return. Limit can range between 1 and 100, and the default is 10.

            - starting_after: typing.Optional[InvoiceId]. The ID of the invoice to start after. If not provided, the first page of invoices will be returned.

            - search: typing.Optional[str]. Filter vendors by name. Partial matches are supported.

            - payer_id: typing.Optional[typing.Union[EntityId, typing.List[EntityId]]]. Filter invoices by payer ID.

            - vendor_id: typing.Optional[typing.Union[EntityId, typing.List[EntityId]]]. Filter invoices by vendor ID.

            - approver_id: typing.Optional[typing.Union[EntityUserId, typing.List[EntityUserId]]]. Filter invoices by assigned approver user ID.

            - invoice_id: typing.Optional[typing.Union[InvoiceId, typing.List[InvoiceId]]]. Filter invoices by invoice ID.

            - status: typing.Optional[typing.Union[InvoiceStatus, typing.List[InvoiceStatus]]]. Invoice status to filter on.

            - include_fees: typing.Optional[bool]. If true, will include fees as part of the response.
        """
        _response = await self._client_wrapper.httpx_client.request(
            "GET",
            urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"entity/{entity_id}/invoices"),
            params=remove_none_from_dict(
                {
                    "excludePayables": exclude_payables,
                    "excludeReceivables": exclude_receivables,
                    "startDate": serialize_datetime(start_date) if start_date is not None else None,
                    "endDate": serialize_datetime(end_date) if end_date is not None else None,
                    "orderBy": order_by,
                    "orderDirection": order_direction,
                    "limit": limit,
                    "startingAfter": starting_after,
                    "search": search,
                    "payerId": payer_id,
                    "vendorId": vendor_id,
                    "approverId": approver_id,
                    "invoiceId": invoice_id,
                    "status": status,
                    "includeFees": include_fees,
                }
            ),
            headers=self._client_wrapper.get_headers(),
            timeout=60,
        )
        try:
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        if 200 <= _response.status_code < 300:
            return pydantic.parse_obj_as(FindInvoiceResponse, _response_json)  # type: ignore
        if "errorName" in _response_json:
            if _response_json["errorName"] == "InvoiceQueryError":
                raise InvoiceQueryError(pydantic.parse_obj_as(str, _response_json["content"]))  # type: ignore
            if _response_json["errorName"] == "AuthHeaderMissingError":
                raise AuthHeaderMissingError()
            if _response_json["errorName"] == "AuthHeaderMalformedError":
                raise AuthHeaderMalformedError(pydantic.parse_obj_as(str, _response_json["content"]))  # type: ignore
            if _response_json["errorName"] == "Unauthorized":
                raise Unauthorized(pydantic.parse_obj_as(str, _response_json["content"]))  # type: ignore
            if _response_json["errorName"] == "Forbidden":
                raise Forbidden(pydantic.parse_obj_as(str, _response_json["content"]))  # type: ignore
            if _response_json["errorName"] == "NotFound":
                raise NotFound(pydantic.parse_obj_as(str, _response_json["content"]))  # type: ignore
            if _response_json["errorName"] == "Unimplemented":
                raise Unimplemented(pydantic.parse_obj_as(str, _response_json["content"]))  # type: ignore
        raise ApiError(status_code=_response.status_code, body=_response_json)

    async def get(
        self, entity_id: EntityId, invoice_id: InvoiceId, *, include_fees: typing.Optional[bool] = None
    ) -> InvoiceResponse:
        """
        Parameters:
            - entity_id: EntityId.

            - invoice_id: InvoiceId. ID of the invoice to retrieve. This can be the full invoice ID (in_11aa2b77-6391-49e4-8c3f-b198009202c1) or the first 8 characters of the ID (11aa2b77).

            - include_fees: typing.Optional[bool]. If true, will include fees as part of the response.
        """
        _response = await self._client_wrapper.httpx_client.request(
            "GET",
            urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"entity/{entity_id}/invoice/{invoice_id}"),
            params=remove_none_from_dict({"includeFees": include_fees}),
            headers=self._client_wrapper.get_headers(),
            timeout=60,
        )
        try:
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        if 200 <= _response.status_code < 300:
            return pydantic.parse_obj_as(InvoiceResponse, _response_json)  # type: ignore
        if "errorName" in _response_json:
            if _response_json["errorName"] == "AuthHeaderMissingError":
                raise AuthHeaderMissingError()
            if _response_json["errorName"] == "AuthHeaderMalformedError":
                raise AuthHeaderMalformedError(pydantic.parse_obj_as(str, _response_json["content"]))  # type: ignore
            if _response_json["errorName"] == "Unauthorized":
                raise Unauthorized(pydantic.parse_obj_as(str, _response_json["content"]))  # type: ignore
            if _response_json["errorName"] == "Forbidden":
                raise Forbidden(pydantic.parse_obj_as(str, _response_json["content"]))  # type: ignore
            if _response_json["errorName"] == "NotFound":
                raise NotFound(pydantic.parse_obj_as(str, _response_json["content"]))  # type: ignore
            if _response_json["errorName"] == "Unimplemented":
                raise Unimplemented(pydantic.parse_obj_as(str, _response_json["content"]))  # type: ignore
        raise ApiError(status_code=_response.status_code, body=_response_json)

    async def metrics(
        self,
        entity_id: EntityId,
        *,
        search: typing.Optional[str] = None,
        exclude_payables: typing.Optional[bool] = None,
        exclude_receivables: typing.Optional[bool] = None,
        payer_id: typing.Optional[typing.Union[EntityId, typing.List[EntityId]]] = None,
        vendor_id: typing.Optional[typing.Union[EntityId, typing.List[EntityId]]] = None,
        approver_id: typing.Optional[typing.Union[EntityUserId, typing.List[EntityUserId]]] = None,
        invoice_id: typing.Optional[typing.Union[InvoiceId, typing.List[InvoiceId]]] = None,
        status: typing.Optional[typing.Union[InvoiceStatus, typing.List[InvoiceStatus]]] = None,
        due_date_start: typing.Optional[dt.datetime] = None,
        due_date_end: typing.Optional[dt.datetime] = None,
        created_date_start: typing.Optional[dt.datetime] = None,
        created_date_end: typing.Optional[dt.datetime] = None,
        currency: typing.Optional[typing.Union[CurrencyCode, typing.List[CurrencyCode]]] = None,
    ) -> typing.List[InvoiceMetricsResponse]:
        """
        Get invoice metrics for an entity with the given filters.

        Parameters:
            - entity_id: EntityId.

            - search: typing.Optional[str]. Filter vendors by name. Partial matches are supported.

            - exclude_payables: typing.Optional[bool]. Only return invoices that are not payable by the entity. This will return only invoices that are receivable by the entity.

            - exclude_receivables: typing.Optional[bool]. Only return invoices that are not receivable by the entity. This will return only invoices that are payable by the entity.

            - payer_id: typing.Optional[typing.Union[EntityId, typing.List[EntityId]]]. Filter invoices by payer ID.

            - vendor_id: typing.Optional[typing.Union[EntityId, typing.List[EntityId]]]. Filter invoices by vendor ID.

            - approver_id: typing.Optional[typing.Union[EntityUserId, typing.List[EntityUserId]]]. Filter invoices by assigned approver user ID.

            - invoice_id: typing.Optional[typing.Union[InvoiceId, typing.List[InvoiceId]]]. Filter invoices by invoice ID.

            - status: typing.Optional[typing.Union[InvoiceStatus, typing.List[InvoiceStatus]]]. Invoice status to filter on

            - due_date_start: typing.Optional[dt.datetime]. Start date for invoice dueDate filter.

            - due_date_end: typing.Optional[dt.datetime]. End date for invoice dueDate filter.

            - created_date_start: typing.Optional[dt.datetime]. Start date for invoice created on date filter.

            - created_date_end: typing.Optional[dt.datetime]. End date for invoice created date filter.

            - currency: typing.Optional[typing.Union[CurrencyCode, typing.List[CurrencyCode]]]. Currency to filter on
        """
        _response = await self._client_wrapper.httpx_client.request(
            "GET",
            urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"entity/{entity_id}/invoice-metrics"),
            params=remove_none_from_dict(
                {
                    "search": search,
                    "excludePayables": exclude_payables,
                    "excludeReceivables": exclude_receivables,
                    "payerId": payer_id,
                    "vendorId": vendor_id,
                    "approverId": approver_id,
                    "invoiceId": invoice_id,
                    "status": status,
                    "dueDateStart": serialize_datetime(due_date_start) if due_date_start is not None else None,
                    "dueDateEnd": serialize_datetime(due_date_end) if due_date_end is not None else None,
                    "createdDateStart": serialize_datetime(created_date_start)
                    if created_date_start is not None
                    else None,
                    "createdDateEnd": serialize_datetime(created_date_end) if created_date_end is not None else None,
                    "currency": currency,
                }
            ),
            headers=self._client_wrapper.get_headers(),
            timeout=60,
        )
        try:
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        if 200 <= _response.status_code < 300:
            return pydantic.parse_obj_as(typing.List[InvoiceMetricsResponse], _response_json)  # type: ignore
        if "errorName" in _response_json:
            if _response_json["errorName"] == "InvoiceQueryError":
                raise InvoiceQueryError(pydantic.parse_obj_as(str, _response_json["content"]))  # type: ignore
            if _response_json["errorName"] == "AuthHeaderMissingError":
                raise AuthHeaderMissingError()
            if _response_json["errorName"] == "AuthHeaderMalformedError":
                raise AuthHeaderMalformedError(pydantic.parse_obj_as(str, _response_json["content"]))  # type: ignore
            if _response_json["errorName"] == "Unauthorized":
                raise Unauthorized(pydantic.parse_obj_as(str, _response_json["content"]))  # type: ignore
            if _response_json["errorName"] == "Forbidden":
                raise Forbidden(pydantic.parse_obj_as(str, _response_json["content"]))  # type: ignore
            if _response_json["errorName"] == "NotFound":
                raise NotFound(pydantic.parse_obj_as(str, _response_json["content"]))  # type: ignore
            if _response_json["errorName"] == "Unimplemented":
                raise Unimplemented(pydantic.parse_obj_as(str, _response_json["content"]))  # type: ignore
        raise ApiError(status_code=_response.status_code, body=_response_json)
