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

import typing

from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.request_options import RequestOptions
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.payor_data_request import PayorDataRequest
from .raw_client import AsyncRawInvoiceClient, RawInvoiceClient
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 InvoiceClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawInvoiceClient(client_wrapper=client_wrapper)

    @property
    def with_raw_response(self) -> RawInvoiceClient:
        """
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        RawInvoiceClient
        """
        return self._raw_client

    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,
    ) -> 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
        -------
        InvoiceResponseWithoutData
            Success

        Examples
        --------
        import datetime

        from payabli import BillData, BillItem, PayorDataRequest, payabli

        client = payabli(
            api_key="YOUR_API_KEY",
        )
        client.invoice.add_invoice(
            entry="8cfec329267",
            customer_data=PayorDataRequest(
                first_name="Tamara",
                last_name="Bagratoni",
                customer_number="3",
            ),
            invoice_data=BillData(
                items=[
                    BillItem(
                        item_product_name="Adventure Consult",
                        item_description="Consultation for Georgian tours",
                        item_cost=100.0,
                        item_qty=1,
                        item_mode=1,
                    ),
                    BillItem(
                        item_product_name="Deposit ",
                        item_description="Deposit for trip planning",
                        item_cost=882.37,
                        item_qty=1,
                    ),
                ],
                invoice_date=datetime.date.fromisoformat(
                    "2025-10-19",
                ),
                invoice_type=0,
                invoice_status=1,
                frequency="one-time",
                invoice_amount=982.37,
                discount=10.0,
                invoice_number="INV-3",
            ),
        )
        """
        _response = self._raw_client.add_invoice(
            entry,
            force_customer_creation=force_customer_creation,
            idempotency_key=idempotency_key,
            customer_data=customer_data,
            invoice_data=invoice_data,
            scheduled_options=scheduled_options,
            request_options=request_options,
        )
        return _response.data

    def delete_attached_from_invoice(
        self, filename: str, id_invoice: int, *, request_options: typing.Optional[RequestOptions] = None
    ) -> 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
        -------
        InvoiceResponseWithoutData
            Success

        Examples
        --------
        from payabli import payabli

        client = payabli(
            api_key="YOUR_API_KEY",
        )
        client.invoice.delete_attached_from_invoice(
            filename="0_Bill.pdf",
            id_invoice=23548884,
        )
        """
        _response = self._raw_client.delete_attached_from_invoice(filename, id_invoice, request_options=request_options)
        return _response.data

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

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

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

        Returns
        -------
        InvoiceResponseWithoutData
            Success

        Examples
        --------
        from payabli import payabli

        client = payabli(
            api_key="YOUR_API_KEY",
        )
        client.invoice.delete_invoice(
            id_invoice=23548884,
        )
        """
        _response = self._raw_client.delete_invoice(id_invoice, request_options=request_options)
        return _response.data

    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,
    ) -> 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
        -------
        InvoiceResponseWithoutData
            Success

        Examples
        --------
        import datetime

        from payabli import BillData, BillItem, payabli

        client = payabli(
            api_key="YOUR_API_KEY",
        )
        client.invoice.edit_invoice(
            id_invoice=332,
            invoice_data=BillData(
                items=[
                    BillItem(
                        item_product_name="Deposit",
                        item_description="Deposit for trip planning",
                        item_cost=882.37,
                        item_qty=1,
                    )
                ],
                invoice_date=datetime.date.fromisoformat(
                    "2025-10-19",
                ),
                invoice_amount=982.37,
                invoice_number="INV-6",
            ),
        )
        """
        _response = self._raw_client.edit_invoice(
            id_invoice,
            force_customer_creation=force_customer_creation,
            customer_data=customer_data,
            invoice_data=invoice_data,
            scheduled_options=scheduled_options,
            request_options=request_options,
        )
        return _response.data

    def get_attached_file_from_invoice(
        self,
        filename: str,
        id_invoice: int,
        *,
        return_object: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> 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
        -------
        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.

        Examples
        --------
        from payabli import payabli

        client = payabli(
            api_key="YOUR_API_KEY",
        )
        client.invoice.get_attached_file_from_invoice(
            filename="filename",
            id_invoice=1,
        )
        """
        _response = self._raw_client.get_attached_file_from_invoice(
            filename, id_invoice, return_object=return_object, request_options=request_options
        )
        return _response.data

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

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

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

        Returns
        -------
        GetInvoiceRecord
            Success. Fields marked optional may return `null` if not set.

        Examples
        --------
        from payabli import payabli

        client = payabli(
            api_key="YOUR_API_KEY",
        )
        client.invoice.get_invoice(
            id_invoice=23548884,
        )
        """
        _response = self._raw_client.get_invoice(id_invoice, request_options=request_options)
        return _response.data

    def get_invoice_number(
        self, entry: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> 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
        -------
        InvoiceNumberResponse
            Success

        Examples
        --------
        from payabli import payabli

        client = payabli(
            api_key="YOUR_API_KEY",
        )
        client.invoice.get_invoice_number(
            entry="8cfec329267",
        )
        """
        _response = self._raw_client.get_invoice_number(entry, request_options=request_options)
        return _response.data

    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,
    ) -> 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
        -------
        QueryInvoiceResponse
            Success. Fields marked optional may return `null` if not set.

        Examples
        --------
        from payabli import payabli

        client = payabli(
            api_key="YOUR_API_KEY",
        )
        client.invoice.list_invoices(
            entry="8cfec329267",
            from_record=251,
            limit_record=0,
            sort_by="desc(field_name)",
        )
        """
        _response = self._raw_client.list_invoices(
            entry,
            export_format=export_format,
            from_record=from_record,
            limit_record=limit_record,
            parameters=parameters,
            sort_by=sort_by,
            request_options=request_options,
        )
        return _response.data

    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,
    ) -> 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
        -------
        QueryInvoiceResponse
            Success. Fields marked optional may return `null` if not set.

        Examples
        --------
        from payabli import payabli

        client = payabli(
            api_key="YOUR_API_KEY",
        )
        client.invoice.list_invoices_org(
            org_id=123,
            from_record=251,
            limit_record=0,
            sort_by="desc(field_name)",
        )
        """
        _response = self._raw_client.list_invoices_org(
            org_id,
            export_format=export_format,
            from_record=from_record,
            limit_record=limit_record,
            parameters=parameters,
            sort_by=sort_by,
            request_options=request_options,
        )
        return _response.data

    def send_invoice(
        self,
        id_invoice: int,
        *,
        attachfile: typing.Optional[bool] = None,
        mail_2: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> 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
        -------
        SendInvoiceResponse
            Success

        Examples
        --------
        from payabli import payabli

        client = payabli(
            api_key="YOUR_API_KEY",
        )
        client.invoice.send_invoice(
            id_invoice=23548884,
            attachfile=True,
            mail_2="tamara@example.com",
        )
        """
        _response = self._raw_client.send_invoice(
            id_invoice, attachfile=attachfile, mail_2=mail_2, request_options=request_options
        )
        return _response.data

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

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

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

        Returns
        -------
        File
            Success

        Examples
        --------
        from payabli import payabli

        client = payabli(
            api_key="YOUR_API_KEY",
        )
        client.invoice.get_invoice_pdf(
            id_invoice=23548884,
        )
        """
        _response = self._raw_client.get_invoice_pdf(id_invoice, request_options=request_options)
        return _response.data


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

    @property
    def with_raw_response(self) -> AsyncRawInvoiceClient:
        """
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        AsyncRawInvoiceClient
        """
        return self._raw_client

    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,
    ) -> 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
        -------
        InvoiceResponseWithoutData
            Success

        Examples
        --------
        import asyncio
        import datetime

        from payabli import Asyncpayabli, BillData, BillItem, PayorDataRequest

        client = Asyncpayabli(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.invoice.add_invoice(
                entry="8cfec329267",
                customer_data=PayorDataRequest(
                    first_name="Tamara",
                    last_name="Bagratoni",
                    customer_number="3",
                ),
                invoice_data=BillData(
                    items=[
                        BillItem(
                            item_product_name="Adventure Consult",
                            item_description="Consultation for Georgian tours",
                            item_cost=100.0,
                            item_qty=1,
                            item_mode=1,
                        ),
                        BillItem(
                            item_product_name="Deposit ",
                            item_description="Deposit for trip planning",
                            item_cost=882.37,
                            item_qty=1,
                        ),
                    ],
                    invoice_date=datetime.date.fromisoformat(
                        "2025-10-19",
                    ),
                    invoice_type=0,
                    invoice_status=1,
                    frequency="one-time",
                    invoice_amount=982.37,
                    discount=10.0,
                    invoice_number="INV-3",
                ),
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.add_invoice(
            entry,
            force_customer_creation=force_customer_creation,
            idempotency_key=idempotency_key,
            customer_data=customer_data,
            invoice_data=invoice_data,
            scheduled_options=scheduled_options,
            request_options=request_options,
        )
        return _response.data

    async def delete_attached_from_invoice(
        self, filename: str, id_invoice: int, *, request_options: typing.Optional[RequestOptions] = None
    ) -> 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
        -------
        InvoiceResponseWithoutData
            Success

        Examples
        --------
        import asyncio

        from payabli import Asyncpayabli

        client = Asyncpayabli(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.invoice.delete_attached_from_invoice(
                filename="0_Bill.pdf",
                id_invoice=23548884,
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.delete_attached_from_invoice(
            filename, id_invoice, request_options=request_options
        )
        return _response.data

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

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

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

        Returns
        -------
        InvoiceResponseWithoutData
            Success

        Examples
        --------
        import asyncio

        from payabli import Asyncpayabli

        client = Asyncpayabli(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.invoice.delete_invoice(
                id_invoice=23548884,
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.delete_invoice(id_invoice, request_options=request_options)
        return _response.data

    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,
    ) -> 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
        -------
        InvoiceResponseWithoutData
            Success

        Examples
        --------
        import asyncio
        import datetime

        from payabli import Asyncpayabli, BillData, BillItem

        client = Asyncpayabli(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.invoice.edit_invoice(
                id_invoice=332,
                invoice_data=BillData(
                    items=[
                        BillItem(
                            item_product_name="Deposit",
                            item_description="Deposit for trip planning",
                            item_cost=882.37,
                            item_qty=1,
                        )
                    ],
                    invoice_date=datetime.date.fromisoformat(
                        "2025-10-19",
                    ),
                    invoice_amount=982.37,
                    invoice_number="INV-6",
                ),
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.edit_invoice(
            id_invoice,
            force_customer_creation=force_customer_creation,
            customer_data=customer_data,
            invoice_data=invoice_data,
            scheduled_options=scheduled_options,
            request_options=request_options,
        )
        return _response.data

    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,
    ) -> 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
        -------
        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.

        Examples
        --------
        import asyncio

        from payabli import Asyncpayabli

        client = Asyncpayabli(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.invoice.get_attached_file_from_invoice(
                filename="filename",
                id_invoice=1,
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.get_attached_file_from_invoice(
            filename, id_invoice, return_object=return_object, request_options=request_options
        )
        return _response.data

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

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

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

        Returns
        -------
        GetInvoiceRecord
            Success. Fields marked optional may return `null` if not set.

        Examples
        --------
        import asyncio

        from payabli import Asyncpayabli

        client = Asyncpayabli(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.invoice.get_invoice(
                id_invoice=23548884,
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.get_invoice(id_invoice, request_options=request_options)
        return _response.data

    async def get_invoice_number(
        self, entry: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> 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
        -------
        InvoiceNumberResponse
            Success

        Examples
        --------
        import asyncio

        from payabli import Asyncpayabli

        client = Asyncpayabli(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.invoice.get_invoice_number(
                entry="8cfec329267",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.get_invoice_number(entry, request_options=request_options)
        return _response.data

    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,
    ) -> 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
        -------
        QueryInvoiceResponse
            Success. Fields marked optional may return `null` if not set.

        Examples
        --------
        import asyncio

        from payabli import Asyncpayabli

        client = Asyncpayabli(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.invoice.list_invoices(
                entry="8cfec329267",
                from_record=251,
                limit_record=0,
                sort_by="desc(field_name)",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.list_invoices(
            entry,
            export_format=export_format,
            from_record=from_record,
            limit_record=limit_record,
            parameters=parameters,
            sort_by=sort_by,
            request_options=request_options,
        )
        return _response.data

    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,
    ) -> 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
        -------
        QueryInvoiceResponse
            Success. Fields marked optional may return `null` if not set.

        Examples
        --------
        import asyncio

        from payabli import Asyncpayabli

        client = Asyncpayabli(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.invoice.list_invoices_org(
                org_id=123,
                from_record=251,
                limit_record=0,
                sort_by="desc(field_name)",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.list_invoices_org(
            org_id,
            export_format=export_format,
            from_record=from_record,
            limit_record=limit_record,
            parameters=parameters,
            sort_by=sort_by,
            request_options=request_options,
        )
        return _response.data

    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,
    ) -> 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
        -------
        SendInvoiceResponse
            Success

        Examples
        --------
        import asyncio

        from payabli import Asyncpayabli

        client = Asyncpayabli(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.invoice.send_invoice(
                id_invoice=23548884,
                attachfile=True,
                mail_2="tamara@example.com",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.send_invoice(
            id_invoice, attachfile=attachfile, mail_2=mail_2, request_options=request_options
        )
        return _response.data

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

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

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

        Returns
        -------
        File
            Success

        Examples
        --------
        import asyncio

        from payabli import Asyncpayabli

        client = Asyncpayabli(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.invoice.get_invoice_pdf(
                id_invoice=23548884,
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.get_invoice_pdf(id_invoice, request_options=request_options)
        return _response.data
