# 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 .bill_query_record_2 import BillQueryRecord2
from .bill_query_response_summary import BillQueryResponseSummary


class BillQueryResponse(UniversalBaseModel):
    """
    Examples
    --------
    import datetime

    from payabli import (
        BillingData,
        BillItem,
        BillQueryRecord2,
        BillQueryRecord2BillApprovalsItem,
        BillQueryResponse,
        BillQueryResponseSummary,
        GeneralEvents,
        VendorOutData,
    )

    BillQueryResponse(
        summary=BillQueryResponseSummary(
            page_size=20,
            total_2_approval=1,
            totalactive=1,
            total_amount=1.1,
            totalamount_2_approval=1.1,
            totalamountactive=1.1,
            totalamountapproved=1.1,
            totalamountcancel=1.1,
            totalamountdisapproved=1.1,
            totalamountintransit=1.1,
            totalamountoverdue=1.1,
            totalamountpaid=1.1,
            totalamountsent_2_approval=1.1,
            totalapproved=1,
            totalcancel=1,
            totaldisapproved=1,
            totalintransit=1,
            totaloverdue=1,
            total_pages=1,
            totalpaid=1,
            total_records=2,
            totalsent_2_approval=1,
        ),
        records=[
            BillQueryRecord2(
                bill_approvals=[
                    BillQueryRecord2BillApprovalsItem(
                        approved=0,
                        approved_time=datetime.datetime.fromisoformat(
                            "2024-03-13 15:54:27+00:00",
                        ),
                        email="lisandra@example.com",
                        id=34,
                    ),
                    BillQueryRecord2BillApprovalsItem(
                        approved=0,
                        approved_time=datetime.datetime.fromisoformat(
                            "2024-03-13 15:54:27+00:00",
                        ),
                        email="jccastillo@example.com",
                        id=293,
                    ),
                ],
                bill_date=datetime.date.fromisoformat(
                    "2025-03-10",
                ),
                bill_events=[
                    GeneralEvents(
                        description="Created Bill",
                        event_time=datetime.datetime.fromisoformat(
                            "2024-03-13 15:54:26+00:00",
                        ),
                        ref_data="00-45e1c2d8b53b72fafc4082f374e68753-ffea4ba4c2ce63ce-00",
                    ),
                    GeneralEvents(
                        description="Sent to Approval",
                        event_time=datetime.datetime.fromisoformat(
                            "2024-03-13 15:54:28+00:00",
                        ),
                        ref_data="00-086a951822211bc2eb1803ed64db9d4f-0f07e0e8c394e481-00",
                    ),
                ],
                bill_items=[
                    BillItem(
                        item_commodity_code="Commod-MI-2024031926",
                        item_cost=200.0,
                        item_description="Consultation price",
                        item_mode=0,
                        item_product_code="Prod-MI-2024031926",
                        item_product_name="Consultation",
                        item_qty=1,
                        item_tax_amount=0.0,
                        item_tax_rate=0.0,
                        item_total_amount=200.0,
                        item_unit_of_measure="per each",
                    )
                ],
                bill_number="MI-bill-2024031926",
                comments="PAYBILL",
                created_at=datetime.datetime.fromisoformat(
                    "2024-03-13 15:54:26+00:00",
                ),
                discount=0.0,
                due_date=datetime.date.fromisoformat(
                    "2025-03-10",
                ),
                external_paypoint_id="micasa-10",
                frequency="one-time",
                id_bill=6104,
                last_updated=datetime.datetime.fromisoformat(
                    "2024-03-13 10:54:26+00:00",
                ),
                lot_number="LOT123",
                mode=0,
                net_amount=200.0,
                parent_org_id=1001,
                parent_org_name="Fitness Hub",
                paypoint_dbaname="MiCasa Sports",
                paypoint_entryname="micasa",
                paypoint_legalname="MiCasa Sports LLC",
                source="web",
                status=2,
                terms="Net30",
                total_amount=200.0,
                vendor=VendorOutData(
                    address_1="1234 Liberdad St.",
                    address_2="Suite 100",
                    billing_data=BillingData(
                        account_number="12345XXXX",
                        bank_account_function=0,
                        bank_account_holder_name="Elena Gomez",
                        bank_account_holder_type="Business",
                        bank_name="Michigan Savings Bank",
                        id=0,
                        routing_account="072000326",
                        type_account="Checking",
                    ),
                    city="Detroit",
                    country="US",
                    ein="XXXXX6789",
                    email="elenag@industriesexample.com",
                    internal_reference_id=1215,
                    mcc="700",
                    name_1="Gomez-Radulescu Industries",
                    name_2="Elena",
                    phone="517-555-0123",
                    state="MI",
                    vendor_id=8723,
                    vendor_number="MI-vendor-2024031926",
                    vendor_status=1,
                    zip="48201",
                ),
            )
        ],
    )
    """

    summary: typing_extensions.Annotated[typing.Optional[BillQueryResponseSummary], FieldMetadata(alias="Summary")] = (
        pydantic.Field(default=None)
    )
    """
    Summary statistics for the bill query response.
    """

    records: typing_extensions.Annotated[
        typing.Optional[typing.List[BillQueryRecord2]], FieldMetadata(alias="Records")
    ] = pydantic.Field(default=None)
    """
    Array of bill records returned by the query.
    """

    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
