# 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 .purchase_order_bulk_upsert_request_purchase_orders_item_items_item import (
    PurchaseOrderBulkUpsertRequestPurchaseOrdersItemItemsItem,
)


class PurchaseOrderBulkUpsertRequestPurchaseOrdersItem(UniversalBaseModel):
    external_id: typing.Optional[str] = None
    po_number: str
    erp_vendor_id: str = pydantic.Field()
    """
    External vendor identifier from ERP system
    """

    erp_vendor_name: typing.Optional[str] = pydantic.Field(default=None)
    """
    Vendor name from ERP system
    """

    date: str
    total_amount: float
    tax: typing.Optional[float] = None
    freight: typing.Optional[float] = None
    miscellaneous_charges: typing.Optional[float] = None
    invoice_number_ref: typing.Optional[str] = pydantic.Field(default=None)
    """
    Invoice reference number
    """

    is2way: typing_extensions.Annotated[typing.Optional[bool], FieldMetadata(alias="is_2_way")] = pydantic.Field(
        default=None
    )
    """
    Whether this is a 2-way match PO
    """

    items: typing.List[PurchaseOrderBulkUpsertRequestPurchaseOrdersItemItemsItem]
    custom_fields: typing.Optional[typing.Dict[str, typing.Any]] = pydantic.Field(default=None)
    """
    Optional custom fields configured for this company's purchase orders
    """

    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
