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

import datetime as dt
import typing

import pydantic
import typing_extensions
from ...core.pydantic_utilities import IS_PYDANTIC_V2, UniversalBaseModel
from ...core.serialization import FieldMetadata
from ...types.bill_pay_out_data import BillPayOutData
from ...types.created_at import CreatedAt
from ...types.dbaname import Dbaname
from ...types.entrypage_id import EntrypageId
from ...types.entrypointfield import Entrypointfield
from ...types.external_paypoint_id import ExternalPaypointId
from ...types.general_events import GeneralEvents
from ...types.last_modified import LastModified
from ...types.legalname import Legalname
from ...types.netamountnullable import Netamountnullable
from ...types.org_parent_id import OrgParentId
from ...types.org_parent_name import OrgParentName
from ...types.paypoint_id import PaypointId
from ...types.query_payment_data import QueryPaymentData
from ...types.source import Source
from ...types.vendor_query_record import VendorQueryRecord


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

    from payabli import (
        BillingDataResponse,
        BillPayOutData,
        ContactsResponse,
        GeneralEvents,
        PaymentDetail,
        QueryPaymentData,
        VendorQueryRecord,
        VendorSummary,
    )
    from payabli.payout_subscription import PayoutSubscriptionQueryRecord

    PayoutSubscriptionQueryRecord(
        id_out_subscription=42,
        status=1,
        events=[
            GeneralEvents(
                description="TransferCreated",
                event_time=datetime.datetime.fromisoformat(
                    "2025-09-01 06:00:00+00:00",
                ),
                extra_data={"key": "value"},
                ref_data="refData",
                source="api",
            )
        ],
        vendor=VendorQueryRecord(
            vendor_number="1234",
            name_1="Herman's Coatings",
            name_2="Herman's Coating Supply Company, LLC",
            ein="123456789",
            phone="2125551234",
            email="example@email.com",
            address_1="123 Ocean Drive",
            address_2="Suite 400",
            city="Bristol",
            state="GA",
            zip="31113",
            country="US",
            mcc="7777",
            location_code="LOC123",
            contacts=ContactsResponse(
                contact_email="eric@martinezcoatings.com",
                contact_name="Eric Martinez",
                contact_phone="5555555555",
                contact_title="Owner",
            ),
            billing_data=BillingDataResponse(
                id=123456,
                account_id="bank-account-001",
                nickname="Main Checking Account",
                bank_name="Example Bank",
                routing_account="123456789",
                account_number="9876543210",
                type_account="Checking",
                bank_account_holder_name="John Doe",
                bank_account_holder_type="Business",
                bank_account_function=2,
                verified=True,
                status=1,
                services=[],
                default=True,
            ),
            vendor_status=1,
            vendor_id=1,
            summary=VendorSummary(
                active_bills=2,
                pending_bills=4,
                in_transit_bills=3,
                paid_bills=18,
                overdue_bills=1,
                approved_bills=5,
                disapproved_bills=1,
                total_bills=34,
                active_bills_amount=1250.75,
                pending_bills_amount=2890.5,
                in_transit_bills_amount=1675.25,
                paid_bills_amount=15420.8,
                overdue_bills_amount=425.0,
                approved_bills_amount=3240.9,
                disapproved_bills_amount=180.0,
                total_bills_amount=25083.2,
            ),
            paypoint_legalname="Sunshine Services, LLC",
            paypoint_dbaname="Sunshine Gutters",
            paypoint_entryname="d193cf9a46",
            parent_org_name="PropertyManager Pro",
            parent_org_id=1000,
            created_date=datetime.datetime.fromisoformat(
                "2022-07-01 15:00:01+00:00",
            ),
            last_updated=datetime.datetime.fromisoformat(
                "2022-07-01 15:00:01+00:00",
            ),
            remit_address_1="123 Walnut Street",
            remit_address_2="Suite 900",
            remit_city="Miami",
            remit_state="FL",
            remit_zip="31113",
            remit_country="US",
            payee_name_1="payeeName1",
            payee_name_2="payeeName2",
            custom_field_1="",
            custom_field_2="",
            customer_vendor_account="123-456",
            internal_reference_id=1000000,
            external_paypoint_id="Paypoint-100",
            stored_methods=[],
        ),
        bill_data=[
            BillPayOutData(
                bill_id=3001,
                invoice_number="INV-5001",
                net_amount="500",
                invoice_date=datetime.date.fromisoformat(
                    "2025-08-01",
                ),
                due_date=datetime.date.fromisoformat(
                    "2025-08-15",
                ),
            )
        ],
        external_paypoint_id="d193cf9a46-10",
        method="ach",
        paypoint_id=255,
        total_amount=500.0,
        net_amount=500.0,
        fee_amount=0.0,
        payment_data=QueryPaymentData(
            account_type="checking",
            holder_name="Herman Coatings",
            initiator="merchant",
            masked_account="XXXXXX5666",
            payment_details=PaymentDetail(
                currency="USD",
                service_fee=0.0,
                total_amount=500.0,
            ),
            sequence="subsequent",
            stored_method_usage_type="recurring",
        ),
        start_date=datetime.datetime.fromisoformat(
            "2025-09-01 00:00:00+00:00",
        ),
        end_date=datetime.datetime.fromisoformat(
            "2026-09-01 00:00:00+00:00",
        ),
        next_date=datetime.datetime.fromisoformat(
            "2025-10-01 00:00:00+00:00",
        ),
        frequency="monthly",
        total_cycles=12,
        left_cycles=11,
        last_run=datetime.datetime.fromisoformat(
            "2025-09-01 06:00:00+00:00",
        ),
        entrypage_id=0,
        until_cancelled=False,
        last_updated=datetime.datetime.fromisoformat(
            "2025-08-01 12:00:00+00:00",
        ),
        created_at=datetime.datetime.fromisoformat(
            "2025-08-01 12:00:00+00:00",
        ),
        paypoint_legalname="Sunshine Services, LLC",
        paypoint_dbaname="Sunshine Gutters",
        paypoint_entryname="d193cf9a46",
        parent_org_name="PropertyManager Pro",
        parent_org_id=236,
        source="api",
    )
    """

    id_out_subscription: typing_extensions.Annotated[
        typing.Optional[int],
        FieldMetadata(alias="idOutSubscription"),
        pydantic.Field(alias="idOutSubscription", description="The payout subscription's ID."),
    ] = None
    status: typing.Optional[int] = pydantic.Field(default=None)
    """
    The payout subscription's status.
    - 0: Paused
    - 1: Active
    """

    events: typing.Optional[typing.List[GeneralEvents]] = pydantic.Field(default=None)
    """
    Events associated with the payout subscription.
    """

    vendor: typing.Optional[VendorQueryRecord] = None
    bill_data: typing_extensions.Annotated[
        typing.Optional[typing.List[BillPayOutData]],
        FieldMetadata(alias="billData"),
        pydantic.Field(alias="billData", description="Bills associated with the payout subscription."),
    ] = None
    external_paypoint_id: typing_extensions.Annotated[
        typing.Optional[ExternalPaypointId],
        FieldMetadata(alias="externalPaypointID"),
        pydantic.Field(alias="externalPaypointID"),
    ] = None
    method: typing.Optional[str] = pydantic.Field(default=None)
    """
    The payout subscription's payment method.
    """

    paypoint_id: typing_extensions.Annotated[
        typing.Optional[PaypointId], FieldMetadata(alias="paypointId"), pydantic.Field(alias="paypointId")
    ] = None
    total_amount: typing_extensions.Annotated[
        typing.Optional[float],
        FieldMetadata(alias="totalAmount"),
        pydantic.Field(alias="totalAmount", description="The payout subscription amount, including any fees."),
    ] = None
    net_amount: typing_extensions.Annotated[
        typing.Optional[Netamountnullable],
        FieldMetadata(alias="netAmount"),
        pydantic.Field(alias="netAmount", description="The payout subscription amount, minus any fees."),
    ] = None
    fee_amount: typing_extensions.Annotated[
        typing.Optional[float],
        FieldMetadata(alias="feeAmount"),
        pydantic.Field(alias="feeAmount", description="Fee applied to the payout subscription."),
    ] = None
    payment_data: typing_extensions.Annotated[
        typing.Optional[QueryPaymentData], FieldMetadata(alias="paymentData"), pydantic.Field(alias="paymentData")
    ] = None
    start_date: typing_extensions.Annotated[
        typing.Optional[dt.datetime],
        FieldMetadata(alias="startDate"),
        pydantic.Field(alias="startDate", description="The payout subscription start date."),
    ] = None
    end_date: typing_extensions.Annotated[
        typing.Optional[dt.datetime],
        FieldMetadata(alias="endDate"),
        pydantic.Field(alias="endDate", description="The payout subscription's end date."),
    ] = None
    next_date: typing_extensions.Annotated[
        typing.Optional[dt.datetime],
        FieldMetadata(alias="nextDate"),
        pydantic.Field(alias="nextDate", description="The next date the payout subscription will be processed."),
    ] = None
    frequency: typing.Optional[str] = pydantic.Field(default=None)
    """
    The payout subscription's frequency.
    """

    total_cycles: typing_extensions.Annotated[
        typing.Optional[int],
        FieldMetadata(alias="totalCycles"),
        pydantic.Field(
            alias="totalCycles", description="The total number of cycles the payout subscription is set to run."
        ),
    ] = None
    left_cycles: typing_extensions.Annotated[
        typing.Optional[int],
        FieldMetadata(alias="leftCycles"),
        pydantic.Field(alias="leftCycles", description="The number of cycles the payout subscription has left."),
    ] = None
    last_run: typing_extensions.Annotated[
        typing.Optional[dt.datetime],
        FieldMetadata(alias="lastRun"),
        pydantic.Field(alias="lastRun", description="The last time the payout subscription was processed."),
    ] = None
    entrypage_id: typing_extensions.Annotated[
        typing.Optional[EntrypageId], FieldMetadata(alias="entrypageId"), pydantic.Field(alias="entrypageId")
    ] = None
    until_cancelled: typing_extensions.Annotated[
        typing.Optional[bool],
        FieldMetadata(alias="untilCancelled"),
        pydantic.Field(
            alias="untilCancelled",
            description="When `true`, the payout subscription has no explicit end date and runs until canceled.",
        ),
    ] = None
    last_updated: typing_extensions.Annotated[
        typing.Optional[LastModified],
        FieldMetadata(alias="lastUpdated"),
        pydantic.Field(alias="lastUpdated", description="The last date and time the payout subscription was updated."),
    ] = None
    created_at: typing_extensions.Annotated[
        typing.Optional[CreatedAt],
        FieldMetadata(alias="createdAt"),
        pydantic.Field(alias="createdAt", description="Timestamp of when the payout subscription was created, in UTC."),
    ] = None
    paypoint_legalname: typing_extensions.Annotated[
        typing.Optional[Legalname],
        FieldMetadata(alias="paypointLegalname"),
        pydantic.Field(alias="paypointLegalname", description="The paypoint's legal name."),
    ] = None
    paypoint_dbaname: typing_extensions.Annotated[
        typing.Optional[Dbaname],
        FieldMetadata(alias="paypointDbaname"),
        pydantic.Field(alias="paypointDbaname", description="The paypoint's DBA name."),
    ] = None
    paypoint_entryname: typing_extensions.Annotated[
        typing.Optional[Entrypointfield],
        FieldMetadata(alias="paypointEntryname"),
        pydantic.Field(alias="paypointEntryname", description="The paypoint's entryname."),
    ] = None
    parent_org_name: typing_extensions.Annotated[
        typing.Optional[OrgParentName], FieldMetadata(alias="parentOrgName"), pydantic.Field(alias="parentOrgName")
    ] = None
    parent_org_id: typing_extensions.Annotated[
        typing.Optional[OrgParentId], FieldMetadata(alias="parentOrgId"), pydantic.Field(alias="parentOrgId")
    ] = None
    source: typing.Optional[Source] = 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
