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

import datetime as dt
import typing

import pydantic
from ..core.pydantic_utilities import IS_PYDANTIC_V2, UniversalBaseModel
from .invoice_detail_object_gl_splits_item import InvoiceDetailObjectGlSplitsItem
from .invoice_detail_object_history_item import InvoiceDetailObjectHistoryItem
from .invoice_detail_object_images_item import InvoiceDetailObjectImagesItem
from .invoice_detail_object_items_processing_result import InvoiceDetailObjectItemsProcessingResult
from .invoice_detail_object_payment_info import InvoiceDetailObjectPaymentInfo
from .invoice_detail_object_payment_status import InvoiceDetailObjectPaymentStatus
from .invoice_detail_object_type import InvoiceDetailObjectType


class InvoiceDetailObject(UniversalBaseModel):
    version: typing.Optional[str] = pydantic.Field(default=None)
    """
    API version
    """

    id: str = pydantic.Field()
    """
    Unique invoice identifier
    """

    number: typing.Optional[str] = pydantic.Field(default=None)
    """
    Invoice number from vendor
    """

    ottimate_vendor_name: typing.Optional[str] = pydantic.Field(default=None)
    """
    Vendor name
    """

    ottimate_location_name: typing.Optional[str] = pydantic.Field(default=None)
    """
    Location name
    """

    invoice_date: typing.Optional[str] = pydantic.Field(default=None)
    """
    Date invoice was issued
    """

    due_date: typing.Optional[str] = pydantic.Field(default=None)
    """
    Payment due date
    """

    total_amount: typing.Optional[float] = pydantic.Field(default=None)
    """
    Total invoice amount
    """

    total_tax: typing.Optional[float] = pydantic.Field(default=None)
    """
    Total tax amount
    """

    currency: typing.Optional[str] = pydantic.Field(default=None)
    """
    Currency code (ISO 4217)
    """

    outstanding_balance: typing.Optional[float] = pydantic.Field(default=None)
    """
    Remaining unpaid amount
    """

    type: typing.Optional[InvoiceDetailObjectType] = pydantic.Field(default=None)
    """
    Type of invoice document
    """

    status: str = pydantic.Field()
    """
    Processing status
    """

    payment_status: InvoiceDetailObjectPaymentStatus = pydantic.Field()
    """
    Payment status
    """

    payment_info: typing.Optional[InvoiceDetailObjectPaymentInfo] = pydantic.Field(default=None)
    """
    Payment information (only present if payment_status is 'paid')
    """

    purchase_order: typing.Optional[str] = pydantic.Field(default=None)
    """
    Associated purchase order number
    """

    created_at: dt.datetime = pydantic.Field()
    """
    Timestamp when invoice was created
    """

    exported_date: typing.Optional[dt.datetime] = pydantic.Field(default=None)
    """
    Date when invoice was exported
    """

    error: typing.Optional[str] = pydantic.Field(default=None)
    """
    Error message if invoice is flagged
    """

    url: typing.Optional[str] = pydantic.Field(default=None)
    """
    URL to view the invoice in the Ottimate dashboard
    """

    images: typing.Optional[typing.List[InvoiceDetailObjectImagesItem]] = pydantic.Field(default=None)
    """
    List of invoice images
    """

    dimensions: typing.Optional[typing.Dict[str, typing.Any]] = pydantic.Field(default=None)
    """
    Header-level dimension mappings. Contains accounting dimensions assigned to the invoice header (e.g., Department, Class, Location).
    """

    gl_splits: typing.Optional[typing.List[InvoiceDetailObjectGlSplitsItem]] = pydantic.Field(default=None)
    """
    GL account splits for the invoice. Returns real splits if they exist, otherwise falls back to virtual splits derived from vendor split rules. null when no splits or rules are configured.
    """

    items_processing_result: typing.Optional[InvoiceDetailObjectItemsProcessingResult] = pydantic.Field(default=None)
    """
    Result of items processing (only present in PATCH response when items were included in request)
    """

    history: typing.Optional[typing.List[InvoiceDetailObjectHistoryItem]] = pydantic.Field(default=None)
    """
    Audit history of the invoice. Only present when expand=history is passed as a query parameter.
    """

    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
