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

import typing
from json.decoder import JSONDecodeError

from ..core.api_error import ApiError
from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.http_response import AsyncHttpResponse, HttpResponse
from ..core.jsonable_encoder import jsonable_encoder
from ..core.pydantic_utilities import parse_obj_as
from ..core.request_options import RequestOptions
from ..core.serialization import convert_and_respect_annotation_metadata
from ..errors.bad_request_error import BadRequestError
from ..errors.internal_server_error import InternalServerError
from ..errors.service_unavailable_error import ServiceUnavailableError
from ..errors.unauthorized_error import UnauthorizedError
from ..types.bill_data import BillData
from ..types.bill_options import BillOptions
from ..types.export_format import ExportFormat
from ..types.file import File
from ..types.file_content import FileContent
from ..types.force_customer_creation import ForceCustomerCreation
from ..types.idempotency_key import IdempotencyKey
from ..types.payabli_api_response import PayabliApiResponse
from ..types.payor_data_request import PayorDataRequest
from .types.get_invoice_record import GetInvoiceRecord
from .types.invoice_number_response import InvoiceNumberResponse
from .types.invoice_response_without_data import InvoiceResponseWithoutData
from .types.query_invoice_response import QueryInvoiceResponse
from .types.send_invoice_response import SendInvoiceResponse

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


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

    def add_invoice(
        self,
        entry: str,
        *,
        force_customer_creation: typing.Optional[ForceCustomerCreation] = None,
        idempotency_key: typing.Optional[IdempotencyKey] = None,
        customer_data: typing.Optional[PayorDataRequest] = OMIT,
        invoice_data: typing.Optional[BillData] = OMIT,
        scheduled_options: typing.Optional[BillOptions] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[InvoiceResponseWithoutData]:
        """
        Creates an invoice in an entrypoint.

        Parameters
        ----------
        entry : str
            The paypoint's entrypoint identifier. [Learn more](/api-reference/api-overview#entrypoint-vs-entry)

        force_customer_creation : typing.Optional[ForceCustomerCreation]

        idempotency_key : typing.Optional[IdempotencyKey]

        customer_data : typing.Optional[PayorDataRequest]
            Object describing the customer/payor. Required for POST requests. Which fields are required depends on the paypoint's custom identifier settings.

        invoice_data : typing.Optional[BillData]
            Object describing the invoice. Required for POST requests.

        scheduled_options : typing.Optional[BillOptions]
            Object with options for scheduled invoices.

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

        Returns
        -------
        HttpResponse[InvoiceResponseWithoutData]
            Success
        """
        _response = self._client_wrapper.httpx_client.request(
            f"Invoice/{jsonable_encoder(entry)}",
            method="POST",
            params={
                "forceCustomerCreation": force_customer_creation,
            },
            json={
                "customerData": convert_and_respect_annotation_metadata(
                    object_=customer_data, annotation=PayorDataRequest, direction="write"
                ),
                "invoiceData": convert_and_respect_annotation_metadata(
                    object_=invoice_data, annotation=BillData, direction="write"
                ),
                "scheduledOptions": convert_and_respect_annotation_metadata(
                    object_=scheduled_options, annotation=BillOptions, direction="write"
                ),
            },
            headers={
                "content-type": "application/json",
                "idempotencyKey": str(idempotency_key) if idempotency_key is not None else None,
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    InvoiceResponseWithoutData,
                    parse_obj_as(
                        type_=InvoiceResponseWithoutData,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 503:
                raise ServiceUnavailableError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PayabliApiResponse,
                        parse_obj_as(
                            type_=PayabliApiResponse,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def delete_attached_from_invoice(
        self, filename: str, id_invoice: int, *, request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[InvoiceResponseWithoutData]:
        """
        Deletes an invoice that's attached to a file.

        Parameters
        ----------
        filename : str
            The filename in Payabli. Filename is `zipName` in response to a request to `/api/Invoice/{idInvoice}`. Here, the filename is `0_Bill.pdf``.
            "DocumentsRef": {
              "zipfile": "inva_269.zip",
              "filelist": [
                {
                  "originalName": "Bill.pdf",
                  "zipName": "0_Bill.pdf",
                  "descriptor": null
                }
              ]
            }

        id_invoice : int
            Invoice ID

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

        Returns
        -------
        HttpResponse[InvoiceResponseWithoutData]
            Success
        """
        _response = self._client_wrapper.httpx_client.request(
            f"Invoice/attachedFileFromInvoice/{jsonable_encoder(id_invoice)}/{jsonable_encoder(filename)}",
            method="DELETE",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    InvoiceResponseWithoutData,
                    parse_obj_as(
                        type_=InvoiceResponseWithoutData,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 503:
                raise ServiceUnavailableError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PayabliApiResponse,
                        parse_obj_as(
                            type_=PayabliApiResponse,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def delete_invoice(
        self, id_invoice: int, *, request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[InvoiceResponseWithoutData]:
        """
        Deletes a single invoice from an entrypoint.

        Parameters
        ----------
        id_invoice : int
            Invoice ID

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

        Returns
        -------
        HttpResponse[InvoiceResponseWithoutData]
            Success
        """
        _response = self._client_wrapper.httpx_client.request(
            f"Invoice/{jsonable_encoder(id_invoice)}",
            method="DELETE",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    InvoiceResponseWithoutData,
                    parse_obj_as(
                        type_=InvoiceResponseWithoutData,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 503:
                raise ServiceUnavailableError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PayabliApiResponse,
                        parse_obj_as(
                            type_=PayabliApiResponse,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def edit_invoice(
        self,
        id_invoice: int,
        *,
        force_customer_creation: typing.Optional[bool] = None,
        customer_data: typing.Optional[PayorDataRequest] = OMIT,
        invoice_data: typing.Optional[BillData] = OMIT,
        scheduled_options: typing.Optional[BillOptions] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[InvoiceResponseWithoutData]:
        """
        Updates details for a single invoice in an entrypoint.

        Parameters
        ----------
        id_invoice : int
            Invoice ID

        force_customer_creation : typing.Optional[bool]
            When `true`, the request creates a new customer record, regardless of whether customer identifiers match an existing customer.

        customer_data : typing.Optional[PayorDataRequest]
            Object describing the customer/payor. Required for POST requests. Which fields are required depends on the paypoint's custom identifier settings.

        invoice_data : typing.Optional[BillData]
            Object describing the invoice. Required for POST requests.

        scheduled_options : typing.Optional[BillOptions]
            Object with options for scheduled invoices.

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

        Returns
        -------
        HttpResponse[InvoiceResponseWithoutData]
            Success
        """
        _response = self._client_wrapper.httpx_client.request(
            f"Invoice/{jsonable_encoder(id_invoice)}",
            method="PUT",
            params={
                "forceCustomerCreation": force_customer_creation,
            },
            json={
                "customerData": convert_and_respect_annotation_metadata(
                    object_=customer_data, annotation=PayorDataRequest, direction="write"
                ),
                "invoiceData": convert_and_respect_annotation_metadata(
                    object_=invoice_data, annotation=BillData, direction="write"
                ),
                "scheduledOptions": convert_and_respect_annotation_metadata(
                    object_=scheduled_options, annotation=BillOptions, direction="write"
                ),
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    InvoiceResponseWithoutData,
                    parse_obj_as(
                        type_=InvoiceResponseWithoutData,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 503:
                raise ServiceUnavailableError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PayabliApiResponse,
                        parse_obj_as(
                            type_=PayabliApiResponse,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def get_attached_file_from_invoice(
        self,
        filename: str,
        id_invoice: int,
        *,
        return_object: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[FileContent]:
        """
        Retrieves a file attached to an invoice.

        Parameters
        ----------
        filename : str
            The filename in Payabli. Filename is `zipName` in the response to a request to `/api/Invoice/{idInvoice}`. Here, the filename is `0_Bill.pdf``.
            ```
              "DocumentsRef": {
                "zipfile": "inva_269.zip",
                "filelist": [
                  {
                    "originalName": "Bill.pdf",
                    "zipName": "0_Bill.pdf",
                    "descriptor": null
                  }
                ]
              }
              ```

        id_invoice : int
            Invoice ID

        return_object : typing.Optional[bool]
            When `true`, the request returns the file content as a Base64-encoded string.

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

        Returns
        -------
        HttpResponse[FileContent]
            A successful response returns a binary file when `returnObject` is `false`. When `returnObject` is `true`, the response contains the file content as a Base64-encoded string in an object. Due to technical limitations, only the object response is documented here.
        """
        _response = self._client_wrapper.httpx_client.request(
            f"Invoice/attachedFileFromInvoice/{jsonable_encoder(id_invoice)}/{jsonable_encoder(filename)}",
            method="GET",
            params={
                "returnObject": return_object,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    FileContent,
                    parse_obj_as(
                        type_=FileContent,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 503:
                raise ServiceUnavailableError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PayabliApiResponse,
                        parse_obj_as(
                            type_=PayabliApiResponse,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def get_invoice(
        self, id_invoice: int, *, request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[GetInvoiceRecord]:
        """
        Retrieves a single invoice by ID.

        Parameters
        ----------
        id_invoice : int
            Invoice ID

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

        Returns
        -------
        HttpResponse[GetInvoiceRecord]
            Success. Fields marked optional may return `null` if not set.
        """
        _response = self._client_wrapper.httpx_client.request(
            f"Invoice/{jsonable_encoder(id_invoice)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    GetInvoiceRecord,
                    parse_obj_as(
                        type_=GetInvoiceRecord,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 503:
                raise ServiceUnavailableError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PayabliApiResponse,
                        parse_obj_as(
                            type_=PayabliApiResponse,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def get_invoice_number(
        self, entry: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[InvoiceNumberResponse]:
        """
        Retrieves the next available invoice number for a paypoint.

        Parameters
        ----------
        entry : str
            The paypoint's entrypoint identifier. [Learn more](/api-reference/api-overview#entrypoint-vs-entry)

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

        Returns
        -------
        HttpResponse[InvoiceNumberResponse]
            Success
        """
        _response = self._client_wrapper.httpx_client.request(
            f"Invoice/getNumber/{jsonable_encoder(entry)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    InvoiceNumberResponse,
                    parse_obj_as(
                        type_=InvoiceNumberResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 503:
                raise ServiceUnavailableError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PayabliApiResponse,
                        parse_obj_as(
                            type_=PayabliApiResponse,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def list_invoices(
        self,
        entry: str,
        *,
        export_format: typing.Optional[ExportFormat] = None,
        from_record: typing.Optional[int] = None,
        limit_record: typing.Optional[int] = None,
        parameters: typing.Optional[typing.Dict[str, typing.Optional[str]]] = None,
        sort_by: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[QueryInvoiceResponse]:
        """
        Returns a list of invoices for an entrypoint. Use filters to limit results. Include the `exportFormat` query parameter to return the results as a file instead of a JSON response.

        Parameters
        ----------
        entry : str
            The paypoint's entrypoint identifier. [Learn more](/api-reference/api-overview#entrypoint-vs-entry)

        export_format : typing.Optional[ExportFormat]

        from_record : typing.Optional[int]
            The number of records to skip before starting to collect the result set.

        limit_record : typing.Optional[int]
            Max number of records to return for the query. Use `0` or negative value to return all records.

        parameters : typing.Optional[typing.Dict[str, typing.Optional[str]]]
            Collection of field names, conditions, and values used to filter the query

            See [Filters and Conditions Reference](/developers/developer-guides/pay-ops-reporting-engine-overview#filters-and-conditions-reference) for help.

            List of field names accepted:

            - `invoiceDate` (gt, ge, lt, le, eq, ne)
            - `dueDate` (gt, ge, lt, le, eq, ne)
            - `sentDate` (gt, ge, lt, le, eq, ne)
            - `frequency` (in, nin,ne, eq)
            - `invoiceType` (eq, ne)
            - `payTerms` (in, nin, eq, ne)
            - `paypointId` (ne, eq)
            - `totalAmount` (gt, ge, lt, le, eq, ne)
            - `paidAmount` (gt, ge, lt, le, eq, ne)
            - `status` (in, nin, eq, ne)
            - `invoiceNumber` (ct, nct, eq, ne)
            - `purchaseOrder` (ct, nct, eq, ne)
            - `itemProductCode` (ct, nct)
            - `itemDescription` (ct, nct)
            - `customerFirstname` (ct, nct, eq, ne)
            - `customerLastname` (ct, nct, eq, ne)
            - `customerName` (ct, nct)
            - `customerId` (eq, ne)
            - `customerNumber` (ct, nct, eq, ne)
            - `customerCompanyname` (ct, nct, eq, ne)
            - `customerAddress` (ct, nct, eq, ne)
            - `customerCity` (ct, nct, eq, ne)
            - `customerZip` (ct, nct, eq, ne)
            - `customerState` (ct, nct, eq, ne)
            - `customerCountry` (ct, nct, eq, ne)
            - `customerPhone` (ct, nct, eq, ne)
            - `customerEmail` (ct, nct, eq, ne)
            - `customerShippingAddress` (ct, nct, eq, ne)
            - `customerShippingCity` (ct, nct, eq, ne)
            - `customerShippingZip` (ct, nct, eq, ne)
            - `customerShippingState` (ct, nct, eq, ne)
            - `customerShippingCountry` (ct, nct, eq, ne)
            - `orgId` (eq)
            - `paylinkId` (ne, eq)
            - `paypointLegal` (ne, eq, ct, nct)
            - `paypointDba` (ne, eq, ct, nct)
            - `orgName` (ne, eq, ct, nct)
            - `additional-xxx` (ne, eq, ct, nct) where xxx is the additional field name

            List of comparison accepted - enclosed between parentheses:

            - eq or empty => equal
            - gt => greater than
            - ge => greater or equal
            - lt => less than
            - le => less or equal
            - ne => not equal
            - ct => contains
            - nct => not contains
            - in => inside array
            - nin => not inside array

            List of parameters accepted:
            - limitRecord : max number of records for query (default="20", "0" or negative value for all)
            - fromRecord : initial record in query

            Example: totalAmount(gt)=20 return all records with totalAmount greater than 20.00

        sort_by : typing.Optional[str]
            The field name to use for sorting results. Use `desc(field_name)` to sort descending by `field_name`, and use `asc(field_name)` to sort ascending by `field_name`.

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

        Returns
        -------
        HttpResponse[QueryInvoiceResponse]
            Success. Fields marked optional may return `null` if not set.
        """
        _response = self._client_wrapper.httpx_client.request(
            f"Query/invoices/{jsonable_encoder(entry)}",
            method="GET",
            params={
                "exportFormat": export_format,
                "fromRecord": from_record,
                "limitRecord": limit_record,
                "parameters": parameters,
                "sortBy": sort_by,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    QueryInvoiceResponse,
                    parse_obj_as(
                        type_=QueryInvoiceResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 503:
                raise ServiceUnavailableError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PayabliApiResponse,
                        parse_obj_as(
                            type_=PayabliApiResponse,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def list_invoices_org(
        self,
        org_id: int,
        *,
        export_format: typing.Optional[ExportFormat] = None,
        from_record: typing.Optional[int] = None,
        limit_record: typing.Optional[int] = None,
        parameters: typing.Optional[typing.Dict[str, typing.Optional[str]]] = None,
        sort_by: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[QueryInvoiceResponse]:
        """
        Returns a list of invoices for an org. Use filters to limit results. Include the `exportFormat` query parameter to return the results as a file instead of a JSON response.

        Parameters
        ----------
        org_id : int
            The numeric identifier for organization, assigned by Payabli.

        export_format : typing.Optional[ExportFormat]

        from_record : typing.Optional[int]
            The number of records to skip before starting to collect the result set.

        limit_record : typing.Optional[int]
            Max number of records to return for the query. Use `0` or negative value to return all records.

        parameters : typing.Optional[typing.Dict[str, typing.Optional[str]]]
            Collection of field names, conditions, and values used to filter the query

            See [Filters and Conditions Reference](/developers/developer-guides/pay-ops-reporting-engine-overview#filters-and-conditions-reference) for help.

            List of field names accepted:

            - `invoiceDate` (gt, ge, lt, le, eq, ne)
            - `dueDate` (gt, ge, lt, le, eq, ne)
            - `sentDate` (gt, ge, lt, le, eq, ne)
            - `frequency` (in, nin,ne, eq)
            - `invoiceType` (eq, ne)
            - `payTerms` (in, nin, eq, ne)
            - `paypointId` (ne, eq)
            - `totalAmount` (gt, ge, lt, le, eq, ne)
            - `paidAmount` (gt, ge, lt, le, eq, ne)
            - `status` (in, nin, eq, ne)
            - `invoiceNumber` (ct, nct, eq, ne)
            - `purchaseOrder` (ct, nct, eq, ne)
            - `itemProductCode` (ct, nct)
            - `itemDescription` (ct, nct)
            - `customerFirstname` (ct, nct, eq, ne)
            - `customerLastname` (ct, nct, eq, ne)
            - `customerName` (ct, nct)
            - `customerId` (eq, ne)
            - `customerNumber` (ct, nct, eq, ne)
            - `customerCompanyname` (ct, nct, eq, ne)
            - `customerAddress` (ct, nct, eq, ne)
            - `customerCity` (ct, nct, eq, ne)
            - `customerZip` (ct, nct, eq, ne)
            - `customerState` (ct, nct, eq, ne)
            - `customerCountry` (ct, nct, eq, ne)
            - `customerPhone` (ct, nct, eq, ne)
            - `customerEmail` (ct, nct, eq, ne)
            - `customerShippingAddress` (ct, nct, eq, ne)
            - `customerShippingCity` (ct, nct, eq, ne)
            - `customerShippingZip` (ct, nct, eq, ne)
            - `customerShippingState` (ct, nct, eq, ne)
            - `customerShippingCountry` (ct, nct, eq, ne)
            - `orgId` (eq)
            - `paylinkId` (ne, eq)
            - `paypointLegal` (ne, eq, ct, nct)
            - `paypointDba` (ne, eq, ct, nct)
            - `orgName` (ne, eq, ct, nct)
            - `additional-xxx` (ne, eq, ct, nct) where xxx is the additional field name

            List of comparison accepted - enclosed between parentheses:

            - eq or empty => equal
            - gt => greater than
            - ge => greater or equal
            - lt => less than
            - le => less or equal
            - ne => not equal
            - ct => contains
            - nct => not contains
            - in => inside array
            - nin => not inside array

            List of parameters accepted:
            - limitRecord : max number of records for query (default="20", "0" or negative value for all)
            - fromRecord : initial record in query

            Example: totalAmount(gt)=20 return all records with totalAmount greater than 20.00

        sort_by : typing.Optional[str]
            The field name to use for sorting results. Use `desc(field_name)` to sort descending by `field_name`, and use `asc(field_name)` to sort ascending by `field_name`.

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

        Returns
        -------
        HttpResponse[QueryInvoiceResponse]
            Success. Fields marked optional may return `null` if not set.
        """
        _response = self._client_wrapper.httpx_client.request(
            f"Query/invoices/org/{jsonable_encoder(org_id)}",
            method="GET",
            params={
                "exportFormat": export_format,
                "fromRecord": from_record,
                "limitRecord": limit_record,
                "parameters": parameters,
                "sortBy": sort_by,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    QueryInvoiceResponse,
                    parse_obj_as(
                        type_=QueryInvoiceResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 503:
                raise ServiceUnavailableError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PayabliApiResponse,
                        parse_obj_as(
                            type_=PayabliApiResponse,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def send_invoice(
        self,
        id_invoice: int,
        *,
        attachfile: typing.Optional[bool] = None,
        mail_2: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[SendInvoiceResponse]:
        """
        Sends an invoice from an entrypoint via email.

        Parameters
        ----------
        id_invoice : int
            Invoice ID

        attachfile : typing.Optional[bool]
            When `true`, attaches a PDF version of invoice to the email.

        mail_2 : typing.Optional[str]
            Email address where the invoice will be sent to. If this parameter isn't included, Payabli uses the email address on file for the customer owner of the invoice.

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

        Returns
        -------
        HttpResponse[SendInvoiceResponse]
            Success
        """
        _response = self._client_wrapper.httpx_client.request(
            f"Invoice/send/{jsonable_encoder(id_invoice)}",
            method="GET",
            params={
                "attachfile": attachfile,
                "mail2": mail_2,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    SendInvoiceResponse,
                    parse_obj_as(
                        type_=SendInvoiceResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 503:
                raise ServiceUnavailableError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PayabliApiResponse,
                        parse_obj_as(
                            type_=PayabliApiResponse,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def get_invoice_pdf(
        self, id_invoice: int, *, request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[File]:
        """
        Export a single invoice in PDF format.

        Parameters
        ----------
        id_invoice : int
            Invoice ID

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

        Returns
        -------
        HttpResponse[File]
            Success
        """
        _response = self._client_wrapper.httpx_client.request(
            f"Export/invoicePdf/{jsonable_encoder(id_invoice)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    File,
                    parse_obj_as(
                        type_=File,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 503:
                raise ServiceUnavailableError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PayabliApiResponse,
                        parse_obj_as(
                            type_=PayabliApiResponse,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)


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

    async def add_invoice(
        self,
        entry: str,
        *,
        force_customer_creation: typing.Optional[ForceCustomerCreation] = None,
        idempotency_key: typing.Optional[IdempotencyKey] = None,
        customer_data: typing.Optional[PayorDataRequest] = OMIT,
        invoice_data: typing.Optional[BillData] = OMIT,
        scheduled_options: typing.Optional[BillOptions] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[InvoiceResponseWithoutData]:
        """
        Creates an invoice in an entrypoint.

        Parameters
        ----------
        entry : str
            The paypoint's entrypoint identifier. [Learn more](/api-reference/api-overview#entrypoint-vs-entry)

        force_customer_creation : typing.Optional[ForceCustomerCreation]

        idempotency_key : typing.Optional[IdempotencyKey]

        customer_data : typing.Optional[PayorDataRequest]
            Object describing the customer/payor. Required for POST requests. Which fields are required depends on the paypoint's custom identifier settings.

        invoice_data : typing.Optional[BillData]
            Object describing the invoice. Required for POST requests.

        scheduled_options : typing.Optional[BillOptions]
            Object with options for scheduled invoices.

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

        Returns
        -------
        AsyncHttpResponse[InvoiceResponseWithoutData]
            Success
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"Invoice/{jsonable_encoder(entry)}",
            method="POST",
            params={
                "forceCustomerCreation": force_customer_creation,
            },
            json={
                "customerData": convert_and_respect_annotation_metadata(
                    object_=customer_data, annotation=PayorDataRequest, direction="write"
                ),
                "invoiceData": convert_and_respect_annotation_metadata(
                    object_=invoice_data, annotation=BillData, direction="write"
                ),
                "scheduledOptions": convert_and_respect_annotation_metadata(
                    object_=scheduled_options, annotation=BillOptions, direction="write"
                ),
            },
            headers={
                "content-type": "application/json",
                "idempotencyKey": str(idempotency_key) if idempotency_key is not None else None,
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    InvoiceResponseWithoutData,
                    parse_obj_as(
                        type_=InvoiceResponseWithoutData,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 503:
                raise ServiceUnavailableError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PayabliApiResponse,
                        parse_obj_as(
                            type_=PayabliApiResponse,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def delete_attached_from_invoice(
        self, filename: str, id_invoice: int, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[InvoiceResponseWithoutData]:
        """
        Deletes an invoice that's attached to a file.

        Parameters
        ----------
        filename : str
            The filename in Payabli. Filename is `zipName` in response to a request to `/api/Invoice/{idInvoice}`. Here, the filename is `0_Bill.pdf``.
            "DocumentsRef": {
              "zipfile": "inva_269.zip",
              "filelist": [
                {
                  "originalName": "Bill.pdf",
                  "zipName": "0_Bill.pdf",
                  "descriptor": null
                }
              ]
            }

        id_invoice : int
            Invoice ID

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

        Returns
        -------
        AsyncHttpResponse[InvoiceResponseWithoutData]
            Success
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"Invoice/attachedFileFromInvoice/{jsonable_encoder(id_invoice)}/{jsonable_encoder(filename)}",
            method="DELETE",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    InvoiceResponseWithoutData,
                    parse_obj_as(
                        type_=InvoiceResponseWithoutData,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 503:
                raise ServiceUnavailableError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PayabliApiResponse,
                        parse_obj_as(
                            type_=PayabliApiResponse,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def delete_invoice(
        self, id_invoice: int, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[InvoiceResponseWithoutData]:
        """
        Deletes a single invoice from an entrypoint.

        Parameters
        ----------
        id_invoice : int
            Invoice ID

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

        Returns
        -------
        AsyncHttpResponse[InvoiceResponseWithoutData]
            Success
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"Invoice/{jsonable_encoder(id_invoice)}",
            method="DELETE",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    InvoiceResponseWithoutData,
                    parse_obj_as(
                        type_=InvoiceResponseWithoutData,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 503:
                raise ServiceUnavailableError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PayabliApiResponse,
                        parse_obj_as(
                            type_=PayabliApiResponse,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def edit_invoice(
        self,
        id_invoice: int,
        *,
        force_customer_creation: typing.Optional[bool] = None,
        customer_data: typing.Optional[PayorDataRequest] = OMIT,
        invoice_data: typing.Optional[BillData] = OMIT,
        scheduled_options: typing.Optional[BillOptions] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[InvoiceResponseWithoutData]:
        """
        Updates details for a single invoice in an entrypoint.

        Parameters
        ----------
        id_invoice : int
            Invoice ID

        force_customer_creation : typing.Optional[bool]
            When `true`, the request creates a new customer record, regardless of whether customer identifiers match an existing customer.

        customer_data : typing.Optional[PayorDataRequest]
            Object describing the customer/payor. Required for POST requests. Which fields are required depends on the paypoint's custom identifier settings.

        invoice_data : typing.Optional[BillData]
            Object describing the invoice. Required for POST requests.

        scheduled_options : typing.Optional[BillOptions]
            Object with options for scheduled invoices.

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

        Returns
        -------
        AsyncHttpResponse[InvoiceResponseWithoutData]
            Success
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"Invoice/{jsonable_encoder(id_invoice)}",
            method="PUT",
            params={
                "forceCustomerCreation": force_customer_creation,
            },
            json={
                "customerData": convert_and_respect_annotation_metadata(
                    object_=customer_data, annotation=PayorDataRequest, direction="write"
                ),
                "invoiceData": convert_and_respect_annotation_metadata(
                    object_=invoice_data, annotation=BillData, direction="write"
                ),
                "scheduledOptions": convert_and_respect_annotation_metadata(
                    object_=scheduled_options, annotation=BillOptions, direction="write"
                ),
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    InvoiceResponseWithoutData,
                    parse_obj_as(
                        type_=InvoiceResponseWithoutData,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 503:
                raise ServiceUnavailableError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PayabliApiResponse,
                        parse_obj_as(
                            type_=PayabliApiResponse,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def get_attached_file_from_invoice(
        self,
        filename: str,
        id_invoice: int,
        *,
        return_object: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[FileContent]:
        """
        Retrieves a file attached to an invoice.

        Parameters
        ----------
        filename : str
            The filename in Payabli. Filename is `zipName` in the response to a request to `/api/Invoice/{idInvoice}`. Here, the filename is `0_Bill.pdf``.
            ```
              "DocumentsRef": {
                "zipfile": "inva_269.zip",
                "filelist": [
                  {
                    "originalName": "Bill.pdf",
                    "zipName": "0_Bill.pdf",
                    "descriptor": null
                  }
                ]
              }
              ```

        id_invoice : int
            Invoice ID

        return_object : typing.Optional[bool]
            When `true`, the request returns the file content as a Base64-encoded string.

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

        Returns
        -------
        AsyncHttpResponse[FileContent]
            A successful response returns a binary file when `returnObject` is `false`. When `returnObject` is `true`, the response contains the file content as a Base64-encoded string in an object. Due to technical limitations, only the object response is documented here.
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"Invoice/attachedFileFromInvoice/{jsonable_encoder(id_invoice)}/{jsonable_encoder(filename)}",
            method="GET",
            params={
                "returnObject": return_object,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    FileContent,
                    parse_obj_as(
                        type_=FileContent,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 503:
                raise ServiceUnavailableError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PayabliApiResponse,
                        parse_obj_as(
                            type_=PayabliApiResponse,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def get_invoice(
        self, id_invoice: int, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[GetInvoiceRecord]:
        """
        Retrieves a single invoice by ID.

        Parameters
        ----------
        id_invoice : int
            Invoice ID

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

        Returns
        -------
        AsyncHttpResponse[GetInvoiceRecord]
            Success. Fields marked optional may return `null` if not set.
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"Invoice/{jsonable_encoder(id_invoice)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    GetInvoiceRecord,
                    parse_obj_as(
                        type_=GetInvoiceRecord,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 503:
                raise ServiceUnavailableError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PayabliApiResponse,
                        parse_obj_as(
                            type_=PayabliApiResponse,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def get_invoice_number(
        self, entry: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[InvoiceNumberResponse]:
        """
        Retrieves the next available invoice number for a paypoint.

        Parameters
        ----------
        entry : str
            The paypoint's entrypoint identifier. [Learn more](/api-reference/api-overview#entrypoint-vs-entry)

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

        Returns
        -------
        AsyncHttpResponse[InvoiceNumberResponse]
            Success
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"Invoice/getNumber/{jsonable_encoder(entry)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    InvoiceNumberResponse,
                    parse_obj_as(
                        type_=InvoiceNumberResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 503:
                raise ServiceUnavailableError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PayabliApiResponse,
                        parse_obj_as(
                            type_=PayabliApiResponse,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def list_invoices(
        self,
        entry: str,
        *,
        export_format: typing.Optional[ExportFormat] = None,
        from_record: typing.Optional[int] = None,
        limit_record: typing.Optional[int] = None,
        parameters: typing.Optional[typing.Dict[str, typing.Optional[str]]] = None,
        sort_by: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[QueryInvoiceResponse]:
        """
        Returns a list of invoices for an entrypoint. Use filters to limit results. Include the `exportFormat` query parameter to return the results as a file instead of a JSON response.

        Parameters
        ----------
        entry : str
            The paypoint's entrypoint identifier. [Learn more](/api-reference/api-overview#entrypoint-vs-entry)

        export_format : typing.Optional[ExportFormat]

        from_record : typing.Optional[int]
            The number of records to skip before starting to collect the result set.

        limit_record : typing.Optional[int]
            Max number of records to return for the query. Use `0` or negative value to return all records.

        parameters : typing.Optional[typing.Dict[str, typing.Optional[str]]]
            Collection of field names, conditions, and values used to filter the query

            See [Filters and Conditions Reference](/developers/developer-guides/pay-ops-reporting-engine-overview#filters-and-conditions-reference) for help.

            List of field names accepted:

            - `invoiceDate` (gt, ge, lt, le, eq, ne)
            - `dueDate` (gt, ge, lt, le, eq, ne)
            - `sentDate` (gt, ge, lt, le, eq, ne)
            - `frequency` (in, nin,ne, eq)
            - `invoiceType` (eq, ne)
            - `payTerms` (in, nin, eq, ne)
            - `paypointId` (ne, eq)
            - `totalAmount` (gt, ge, lt, le, eq, ne)
            - `paidAmount` (gt, ge, lt, le, eq, ne)
            - `status` (in, nin, eq, ne)
            - `invoiceNumber` (ct, nct, eq, ne)
            - `purchaseOrder` (ct, nct, eq, ne)
            - `itemProductCode` (ct, nct)
            - `itemDescription` (ct, nct)
            - `customerFirstname` (ct, nct, eq, ne)
            - `customerLastname` (ct, nct, eq, ne)
            - `customerName` (ct, nct)
            - `customerId` (eq, ne)
            - `customerNumber` (ct, nct, eq, ne)
            - `customerCompanyname` (ct, nct, eq, ne)
            - `customerAddress` (ct, nct, eq, ne)
            - `customerCity` (ct, nct, eq, ne)
            - `customerZip` (ct, nct, eq, ne)
            - `customerState` (ct, nct, eq, ne)
            - `customerCountry` (ct, nct, eq, ne)
            - `customerPhone` (ct, nct, eq, ne)
            - `customerEmail` (ct, nct, eq, ne)
            - `customerShippingAddress` (ct, nct, eq, ne)
            - `customerShippingCity` (ct, nct, eq, ne)
            - `customerShippingZip` (ct, nct, eq, ne)
            - `customerShippingState` (ct, nct, eq, ne)
            - `customerShippingCountry` (ct, nct, eq, ne)
            - `orgId` (eq)
            - `paylinkId` (ne, eq)
            - `paypointLegal` (ne, eq, ct, nct)
            - `paypointDba` (ne, eq, ct, nct)
            - `orgName` (ne, eq, ct, nct)
            - `additional-xxx` (ne, eq, ct, nct) where xxx is the additional field name

            List of comparison accepted - enclosed between parentheses:

            - eq or empty => equal
            - gt => greater than
            - ge => greater or equal
            - lt => less than
            - le => less or equal
            - ne => not equal
            - ct => contains
            - nct => not contains
            - in => inside array
            - nin => not inside array

            List of parameters accepted:
            - limitRecord : max number of records for query (default="20", "0" or negative value for all)
            - fromRecord : initial record in query

            Example: totalAmount(gt)=20 return all records with totalAmount greater than 20.00

        sort_by : typing.Optional[str]
            The field name to use for sorting results. Use `desc(field_name)` to sort descending by `field_name`, and use `asc(field_name)` to sort ascending by `field_name`.

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

        Returns
        -------
        AsyncHttpResponse[QueryInvoiceResponse]
            Success. Fields marked optional may return `null` if not set.
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"Query/invoices/{jsonable_encoder(entry)}",
            method="GET",
            params={
                "exportFormat": export_format,
                "fromRecord": from_record,
                "limitRecord": limit_record,
                "parameters": parameters,
                "sortBy": sort_by,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    QueryInvoiceResponse,
                    parse_obj_as(
                        type_=QueryInvoiceResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 503:
                raise ServiceUnavailableError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PayabliApiResponse,
                        parse_obj_as(
                            type_=PayabliApiResponse,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def list_invoices_org(
        self,
        org_id: int,
        *,
        export_format: typing.Optional[ExportFormat] = None,
        from_record: typing.Optional[int] = None,
        limit_record: typing.Optional[int] = None,
        parameters: typing.Optional[typing.Dict[str, typing.Optional[str]]] = None,
        sort_by: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[QueryInvoiceResponse]:
        """
        Returns a list of invoices for an org. Use filters to limit results. Include the `exportFormat` query parameter to return the results as a file instead of a JSON response.

        Parameters
        ----------
        org_id : int
            The numeric identifier for organization, assigned by Payabli.

        export_format : typing.Optional[ExportFormat]

        from_record : typing.Optional[int]
            The number of records to skip before starting to collect the result set.

        limit_record : typing.Optional[int]
            Max number of records to return for the query. Use `0` or negative value to return all records.

        parameters : typing.Optional[typing.Dict[str, typing.Optional[str]]]
            Collection of field names, conditions, and values used to filter the query

            See [Filters and Conditions Reference](/developers/developer-guides/pay-ops-reporting-engine-overview#filters-and-conditions-reference) for help.

            List of field names accepted:

            - `invoiceDate` (gt, ge, lt, le, eq, ne)
            - `dueDate` (gt, ge, lt, le, eq, ne)
            - `sentDate` (gt, ge, lt, le, eq, ne)
            - `frequency` (in, nin,ne, eq)
            - `invoiceType` (eq, ne)
            - `payTerms` (in, nin, eq, ne)
            - `paypointId` (ne, eq)
            - `totalAmount` (gt, ge, lt, le, eq, ne)
            - `paidAmount` (gt, ge, lt, le, eq, ne)
            - `status` (in, nin, eq, ne)
            - `invoiceNumber` (ct, nct, eq, ne)
            - `purchaseOrder` (ct, nct, eq, ne)
            - `itemProductCode` (ct, nct)
            - `itemDescription` (ct, nct)
            - `customerFirstname` (ct, nct, eq, ne)
            - `customerLastname` (ct, nct, eq, ne)
            - `customerName` (ct, nct)
            - `customerId` (eq, ne)
            - `customerNumber` (ct, nct, eq, ne)
            - `customerCompanyname` (ct, nct, eq, ne)
            - `customerAddress` (ct, nct, eq, ne)
            - `customerCity` (ct, nct, eq, ne)
            - `customerZip` (ct, nct, eq, ne)
            - `customerState` (ct, nct, eq, ne)
            - `customerCountry` (ct, nct, eq, ne)
            - `customerPhone` (ct, nct, eq, ne)
            - `customerEmail` (ct, nct, eq, ne)
            - `customerShippingAddress` (ct, nct, eq, ne)
            - `customerShippingCity` (ct, nct, eq, ne)
            - `customerShippingZip` (ct, nct, eq, ne)
            - `customerShippingState` (ct, nct, eq, ne)
            - `customerShippingCountry` (ct, nct, eq, ne)
            - `orgId` (eq)
            - `paylinkId` (ne, eq)
            - `paypointLegal` (ne, eq, ct, nct)
            - `paypointDba` (ne, eq, ct, nct)
            - `orgName` (ne, eq, ct, nct)
            - `additional-xxx` (ne, eq, ct, nct) where xxx is the additional field name

            List of comparison accepted - enclosed between parentheses:

            - eq or empty => equal
            - gt => greater than
            - ge => greater or equal
            - lt => less than
            - le => less or equal
            - ne => not equal
            - ct => contains
            - nct => not contains
            - in => inside array
            - nin => not inside array

            List of parameters accepted:
            - limitRecord : max number of records for query (default="20", "0" or negative value for all)
            - fromRecord : initial record in query

            Example: totalAmount(gt)=20 return all records with totalAmount greater than 20.00

        sort_by : typing.Optional[str]
            The field name to use for sorting results. Use `desc(field_name)` to sort descending by `field_name`, and use `asc(field_name)` to sort ascending by `field_name`.

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

        Returns
        -------
        AsyncHttpResponse[QueryInvoiceResponse]
            Success. Fields marked optional may return `null` if not set.
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"Query/invoices/org/{jsonable_encoder(org_id)}",
            method="GET",
            params={
                "exportFormat": export_format,
                "fromRecord": from_record,
                "limitRecord": limit_record,
                "parameters": parameters,
                "sortBy": sort_by,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    QueryInvoiceResponse,
                    parse_obj_as(
                        type_=QueryInvoiceResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 503:
                raise ServiceUnavailableError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PayabliApiResponse,
                        parse_obj_as(
                            type_=PayabliApiResponse,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def send_invoice(
        self,
        id_invoice: int,
        *,
        attachfile: typing.Optional[bool] = None,
        mail_2: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[SendInvoiceResponse]:
        """
        Sends an invoice from an entrypoint via email.

        Parameters
        ----------
        id_invoice : int
            Invoice ID

        attachfile : typing.Optional[bool]
            When `true`, attaches a PDF version of invoice to the email.

        mail_2 : typing.Optional[str]
            Email address where the invoice will be sent to. If this parameter isn't included, Payabli uses the email address on file for the customer owner of the invoice.

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

        Returns
        -------
        AsyncHttpResponse[SendInvoiceResponse]
            Success
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"Invoice/send/{jsonable_encoder(id_invoice)}",
            method="GET",
            params={
                "attachfile": attachfile,
                "mail2": mail_2,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    SendInvoiceResponse,
                    parse_obj_as(
                        type_=SendInvoiceResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 503:
                raise ServiceUnavailableError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PayabliApiResponse,
                        parse_obj_as(
                            type_=PayabliApiResponse,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def get_invoice_pdf(
        self, id_invoice: int, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[File]:
        """
        Export a single invoice in PDF format.

        Parameters
        ----------
        id_invoice : int
            Invoice ID

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

        Returns
        -------
        AsyncHttpResponse[File]
            Success
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"Export/invoicePdf/{jsonable_encoder(id_invoice)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    File,
                    parse_obj_as(
                        type_=File,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 503:
                raise ServiceUnavailableError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PayabliApiResponse,
                        parse_obj_as(
                            type_=PayabliApiResponse,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
