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

import typing

import pydantic
import typing_extensions
from ...core.pydantic_utilities import IS_PYDANTIC_V2, UniversalBaseModel
from ...core.serialization import FieldMetadata
from ...types.bill_events import BillEvents
from ...types.bill_item import BillItem
from ...types.bill_options import BillOptions
from ...types.created_at import CreatedAt
from ...types.customer_id import CustomerId
from ...types.datenullable import Datenullable
from ...types.datetime_nullable import DatetimeNullable
from ...types.dbaname import Dbaname
from ...types.discount import Discount
from ...types.documents_ref import DocumentsRef
from ...types.duty_amount import DutyAmount
from ...types.email import Email
from ...types.entrypointfield import Entrypointfield
from ...types.external_paypoint_id import ExternalPaypointId
from ...types.freight_amount import FreightAmount
from ...types.frequency import Frequency
from ...types.invoice_amount import InvoiceAmount
from ...types.invoice_type import InvoiceType
from ...types.invoicenumber import Invoicenumber
from ...types.invoicestatus import Invoicestatus
from ...types.legalname import Legalname
from ...types.org_parent_name import OrgParentName
from ...types.orgid import Orgid
from ...types.page_identifier import PageIdentifier
from ...types.payor_data_response import PayorDataResponse
from ...types.paypoint_id import PaypointId
from ...types.purchase_order import PurchaseOrder
from ...types.shipping_from_zip import ShippingFromZip
from ...types.shippingaddress import Shippingaddress
from ...types.shippingaddressadditional import Shippingaddressadditional
from ...types.shippingcity import Shippingcity
from ...types.shippingcountry import Shippingcountry
from ...types.shippingstate import Shippingstate
from ...types.shippingzip import Shippingzip
from ...types.summary_commodity_code import SummaryCommodityCode
from ...types.tax import Tax
from ...types.terms import Terms
from ...types.terms_conditions import TermsConditions
from .invoice_id import InvoiceId
from .invoice_paid_amount import InvoicePaidAmount


class QueryInvoiceResponseRecordsItem(UniversalBaseModel):
    invoice_id: typing_extensions.Annotated[InvoiceId, FieldMetadata(alias="invoiceId")]
    customer_id: typing_extensions.Annotated[CustomerId, FieldMetadata(alias="customerId")]
    paypoint_id: typing_extensions.Annotated[PaypointId, FieldMetadata(alias="paypointId")]
    invoice_number: typing_extensions.Annotated[Invoicenumber, FieldMetadata(alias="invoiceNumber")]
    invoice_date: typing_extensions.Annotated[Datenullable, FieldMetadata(alias="invoiceDate")] = pydantic.Field()
    """
    Invoice date in any of the accepted formats: YYYY-MM-DD, MM/DD/YYYY.
    """

    invoice_due_date: typing_extensions.Annotated[Datenullable, FieldMetadata(alias="invoiceDueDate")] = (
        pydantic.Field()
    )
    """
    Invoice due date in any of the accepted formats: YYYY-MM-DD, MM/DD/YYYY.
    """

    invoice_sent_date: typing_extensions.Annotated[Datenullable, FieldMetadata(alias="invoiceSentDate")] = (
        pydantic.Field()
    )
    """
    Invoice sent date in any of the accepted formats: YYYY-MM-DD, MM/DD/YYYY.
    """

    invoice_end_date: typing_extensions.Annotated[Datenullable, FieldMetadata(alias="invoiceEndDate")] = (
        pydantic.Field()
    )
    """
    The end date for a scheduled invoice cycle (`invoiceType` = 1).
    """

    last_payment_date: typing_extensions.Annotated[
        typing.Optional[DatetimeNullable], FieldMetadata(alias="lastPaymentDate")
    ] = pydantic.Field(default=None)
    """
    Timestamp of last payment.
    """

    created_at: typing_extensions.Annotated[CreatedAt, FieldMetadata(alias="createdAt")]
    invoice_status: typing_extensions.Annotated[Invoicestatus, FieldMetadata(alias="invoiceStatus")]
    invoice_type: typing_extensions.Annotated[InvoiceType, FieldMetadata(alias="invoiceType")]
    frequency: Frequency = pydantic.Field()
    """
    Frequency of scheduled invoice.
    """

    payment_terms: typing_extensions.Annotated[Terms, FieldMetadata(alias="paymentTerms")]
    terms_conditions: typing_extensions.Annotated[
        typing.Optional[TermsConditions], FieldMetadata(alias="termsConditions")
    ] = None
    notes: typing.Optional[str] = pydantic.Field(default=None)
    """
    Invoice notes.
    """

    tax: Tax
    discount: Discount
    invoice_amount: typing_extensions.Annotated[InvoiceAmount, FieldMetadata(alias="invoiceAmount")]
    invoice_paid_amount: typing_extensions.Annotated[InvoicePaidAmount, FieldMetadata(alias="invoicePaidAmount")]
    freight_amount: typing_extensions.Annotated[FreightAmount, FieldMetadata(alias="freightAmount")]
    duty_amount: typing_extensions.Annotated[DutyAmount, FieldMetadata(alias="dutyAmount")]
    purchase_order: typing_extensions.Annotated[
        typing.Optional[PurchaseOrder], FieldMetadata(alias="purchaseOrder")
    ] = None
    first_name: typing_extensions.Annotated[str, FieldMetadata(alias="firstName")] = pydantic.Field()
    """
    First name of the recipient of the invoice.
    """

    last_name: typing_extensions.Annotated[str, FieldMetadata(alias="lastName")] = pydantic.Field()
    """
    Last name of the recipient of the invoice.
    """

    company: typing.Optional[str] = pydantic.Field(default=None)
    """
    Company name of the recipient of the invoice.
    """

    shipping_address_1: typing_extensions.Annotated[Shippingaddress, FieldMetadata(alias="shippingAddress1")]
    shipping_address_2: typing_extensions.Annotated[Shippingaddressadditional, FieldMetadata(alias="shippingAddress2")]
    shipping_city: typing_extensions.Annotated[Shippingcity, FieldMetadata(alias="shippingCity")]
    shipping_state: typing_extensions.Annotated[Shippingstate, FieldMetadata(alias="shippingState")]
    shipping_zip: typing_extensions.Annotated[Shippingzip, FieldMetadata(alias="shippingZip")]
    shipping_from_zip: typing_extensions.Annotated[ShippingFromZip, FieldMetadata(alias="shippingFromZip")]
    shipping_country: typing_extensions.Annotated[Shippingcountry, FieldMetadata(alias="shippingCountry")]
    shipping_email: typing_extensions.Annotated[Email, FieldMetadata(alias="shippingEmail")] = pydantic.Field()
    """
    Shipping recipient's contact email address.
    """

    shipping_phone: typing_extensions.Annotated[str, FieldMetadata(alias="shippingPhone")] = pydantic.Field()
    """
    Recipient phone number.
    """

    summary_commodity_code: typing_extensions.Annotated[
        typing.Optional[SummaryCommodityCode], FieldMetadata(alias="summaryCommodityCode")
    ] = None
    items: typing.List[BillItem] = pydantic.Field()
    """
    Array of line items included in the invoice.
    """

    customer: typing_extensions.Annotated[PayorDataResponse, FieldMetadata(alias="Customer")]
    paylink_id: typing_extensions.Annotated[str, FieldMetadata(alias="paylinkId")]
    bill_events: typing_extensions.Annotated[BillEvents, FieldMetadata(alias="billEvents")]
    scheduled_options: typing_extensions.Annotated[
        typing.Optional[BillOptions], FieldMetadata(alias="scheduledOptions")
    ] = pydantic.Field(default=None)
    """
    Object with options for scheduled invoices.
    """

    paypoint_legalname: typing_extensions.Annotated[Legalname, FieldMetadata(alias="PaypointLegalname")] = (
        pydantic.Field()
    )
    """
    Paypoint's legal name.
    """

    paypoint_dbaname: typing_extensions.Annotated[Dbaname, FieldMetadata(alias="PaypointDbaname")] = pydantic.Field()
    """
    Paypoint's DBA name.
    """

    paypoint_entryname: typing_extensions.Annotated[Entrypointfield, FieldMetadata(alias="PaypointEntryname")] = (
        pydantic.Field()
    )
    """
    Paypoint's entryname.
    """

    parent_org_id: typing_extensions.Annotated[Orgid, FieldMetadata(alias="ParentOrgId")]
    parent_org_name: typing_extensions.Annotated[OrgParentName, FieldMetadata(alias="ParentOrgName")]
    additional_data: typing_extensions.Annotated[
        typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]], FieldMetadata(alias="AdditionalData")
    ] = pydantic.Field(default=None)
    """
    Custom list of key:value pairs. This field is used to store any data related to the invoice or for your system.
    """

    documents_ref: typing_extensions.Annotated[typing.Optional[DocumentsRef], FieldMetadata(alias="DocumentsRef")] = (
        pydantic.Field(default=None)
    )
    """
    Object containing attachments associated to the invoice.
    """

    external_paypoint_id: typing_extensions.Annotated[ExternalPaypointId, FieldMetadata(alias="externalPaypointID")]
    page_identifier: typing_extensions.Annotated[
        typing.Optional[PageIdentifier], FieldMetadata(alias="pageIdentifier")
    ] = None

    if IS_PYDANTIC_V2:
        model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True)  # type: ignore # Pydantic v2
    else:

        class Config:
            frozen = True
            smart_union = True
            extra = pydantic.Extra.allow
