# 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 .accounting_field import AccountingField
from .bill_item import BillItem
from .bill_query_record_2_bill_approvals_item import BillQueryRecord2BillApprovalsItem
from .bill_query_record_2_payment_method import BillQueryRecord2PaymentMethod
from .billstatus import Billstatus
from .created_at import CreatedAt
from .datenullable import Datenullable
from .datetime_nullable import DatetimeNullable
from .dbaname import Dbaname
from .external_paypoint_id import ExternalPaypointId
from .frequency import Frequency
from .general_events import GeneralEvents
from .legalname import Legalname
from .org_parent_name import OrgParentName
from .payment_id_string import PaymentIdString
from .terms import Terms
from .transaction_out_query_record import TransactionOutQueryRecord
from .vendor_out_data import VendorOutData


class BillQueryRecord2(UniversalBaseModel):
    accounting_field_1: typing_extensions.Annotated[
        typing.Optional[AccountingField], FieldMetadata(alias="AccountingField1")
    ] = None
    accounting_field_2: typing_extensions.Annotated[
        typing.Optional[AccountingField], FieldMetadata(alias="AccountingField2")
    ] = None
    additional_data: typing_extensions.Annotated[
        typing.Optional[typing.Dict[str, str]], FieldMetadata(alias="AdditionalData")
    ] = pydantic.Field(default=None)
    """
    Additional data associated with the bill.
    """

    batch_number: typing_extensions.Annotated[typing.Optional[str], FieldMetadata(alias="BatchNumber")] = (
        pydantic.Field(default=None)
    )
    """
    Batch number associated with the bill.
    """

    bill_approvals: typing_extensions.Annotated[
        typing.Optional[typing.List[BillQueryRecord2BillApprovalsItem]], FieldMetadata(alias="billApprovals")
    ] = None
    bill_date: typing_extensions.Annotated[typing.Optional[Datenullable], FieldMetadata(alias="BillDate")] = (
        pydantic.Field(default=None)
    )
    """
    Bill creation date in one of the accepted formats: YYYY-MM-DD, MM/DD/YYYY.
    """

    bill_events: typing_extensions.Annotated[
        typing.Optional[typing.List[GeneralEvents]], FieldMetadata(alias="billEvents")
    ] = pydantic.Field(default=None)
    """
    Events associated with the bill.
    """

    bill_items: typing_extensions.Annotated[
        typing.Optional[typing.List[BillItem]], FieldMetadata(alias="BillItems")
    ] = pydantic.Field(default=None)
    """
    Array of items included in the bill.
    """

    bill_number: typing_extensions.Annotated[typing.Optional[str], FieldMetadata(alias="BillNumber")] = pydantic.Field(
        default=None
    )
    """
    Bill number.
    """

    comments: typing_extensions.Annotated[typing.Optional[str], FieldMetadata(alias="Comments")] = pydantic.Field(
        default=None
    )
    """
    Additional comments on the bill.
    """

    created_at: typing_extensions.Annotated[typing.Optional[CreatedAt], FieldMetadata(alias="CreatedAt")] = (
        pydantic.Field(default=None)
    )
    """
    Timestamp of when bill was created, in UTC.
    """

    discount: typing_extensions.Annotated[typing.Optional[float], FieldMetadata(alias="Discount")] = pydantic.Field(
        default=None
    )
    """
    Discount amount applied to the bill.
    """

    documents_ref: typing_extensions.Annotated[typing.Optional[str], FieldMetadata(alias="DocumentsRef")] = (
        pydantic.Field(default=None)
    )
    """
    Reference to documents associated with the bill.
    """

    due_date: typing_extensions.Annotated[typing.Optional[Datenullable], FieldMetadata(alias="DueDate")] = (
        pydantic.Field(default=None)
    )
    """
    Bill due date in one of the accepted formats: YYYY-MM-DD, MM/DD/YYYY.
    """

    end_date: typing_extensions.Annotated[typing.Optional[Datenullable], FieldMetadata(alias="EndDate")] = (
        pydantic.Field(default=None)
    )
    """
    End date for the bill.
    """

    entity_id: typing_extensions.Annotated[typing.Optional[str], FieldMetadata(alias="EntityID")] = pydantic.Field(
        default=None
    )
    """
    Entity identifier associated with the bill.
    """

    external_paypoint_id: typing_extensions.Annotated[
        typing.Optional[ExternalPaypointId], FieldMetadata(alias="externalPaypointID")
    ] = None
    frequency: typing_extensions.Annotated[typing.Optional[Frequency], FieldMetadata(alias="Frequency")] = (
        pydantic.Field(default=None)
    )
    """
    Frequency for scheduled bills. Applied only in `Mode` = 1.
    """

    id_bill: typing_extensions.Annotated[typing.Optional[int], FieldMetadata(alias="IdBill")] = pydantic.Field(
        default=None
    )
    """
    Identifier of the bill.
    """

    last_updated: typing_extensions.Annotated[typing.Optional[DatetimeNullable], FieldMetadata(alias="LastUpdated")] = (
        pydantic.Field(default=None)
    )
    """
    Timestamp of when bill was last updated, in UTC.
    """

    lot_number: typing_extensions.Annotated[typing.Optional[str], FieldMetadata(alias="LotNumber")] = pydantic.Field(
        default=None
    )
    """
    Lot number associated with the bill.
    """

    mode: typing_extensions.Annotated[typing.Optional[int], FieldMetadata(alias="Mode")] = pydantic.Field(default=None)
    """
    Bill mode: value `0` for single/one-time bills, `1` for scheduled bills.
    """

    net_amount: typing_extensions.Annotated[typing.Optional[float], FieldMetadata(alias="NetAmount")] = pydantic.Field(
        default=None
    )
    """
    Net amount of the bill.
    """

    parent_org_id: typing_extensions.Annotated[typing.Optional[int], FieldMetadata(alias="ParentOrgId")] = (
        pydantic.Field(default=None)
    )
    """
    Parent organization identifier.
    """

    parent_org_name: typing_extensions.Annotated[
        typing.Optional[OrgParentName], FieldMetadata(alias="ParentOrgName")
    ] = None
    payment_id: typing_extensions.Annotated[typing.Optional[PaymentIdString], FieldMetadata(alias="PaymentId")] = None
    payment_method: typing_extensions.Annotated[
        typing.Optional[BillQueryRecord2PaymentMethod], FieldMetadata(alias="PaymentMethod")
    ] = pydantic.Field(default=None)
    """
    Preferred payment method used.
    """

    paylink_id: typing_extensions.Annotated[typing.Optional[str], FieldMetadata(alias="paylinkId")] = pydantic.Field(
        default=None
    )
    """
    Paylink identifier associated with the bill.
    """

    paypoint_dbaname: typing_extensions.Annotated[typing.Optional[Dbaname], FieldMetadata(alias="PaypointDbaname")] = (
        pydantic.Field(default=None)
    )
    """
    The paypoint's DBA name.
    """

    paypoint_entryname: typing_extensions.Annotated[typing.Optional[str], FieldMetadata(alias="PaypointEntryname")] = (
        pydantic.Field(default=None)
    )
    """
    Entry name of the paypoint.
    """

    paypoint_legalname: typing_extensions.Annotated[
        typing.Optional[Legalname], FieldMetadata(alias="PaypointLegalname")
    ] = pydantic.Field(default=None)
    """
    The paypoint's legal name.
    """

    source: typing_extensions.Annotated[typing.Optional[str], FieldMetadata(alias="Source")] = pydantic.Field(
        default=None
    )
    """
    Source of the bill.
    """

    status: typing_extensions.Annotated[typing.Optional[Billstatus], FieldMetadata(alias="Status")] = None
    terms: typing_extensions.Annotated[typing.Optional[Terms], FieldMetadata(alias="Terms")] = pydantic.Field(
        default=None
    )
    """
    The payment terms for invoice. If no terms were defined initially, then response data for this field will default to `N30`.
    """

    total_amount: typing_extensions.Annotated[typing.Optional[float], FieldMetadata(alias="TotalAmount")] = (
        pydantic.Field(default=None)
    )
    """
    Total amount of the bill including taxes and fees.
    """

    transaction: typing_extensions.Annotated[
        typing.Optional[TransactionOutQueryRecord], FieldMetadata(alias="Transaction")
    ] = pydantic.Field(default=None)
    """
    MoneyOut transaction associated to the bill.
    """

    vendor: typing_extensions.Annotated[typing.Optional[VendorOutData], FieldMetadata(alias="Vendor")] = 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
