# 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 .batch_number import BatchNumber
from .bill_data import BillData
from .category import Category
from .created_at import CreatedAt
from .deposit_date import DepositDate
from .expected_deposit_date import ExpectedDepositDate
from .external_paypoint_id import ExternalPaypointId
from .maskedaccount import Maskedaccount
from .netamountnullable import Netamountnullable
from .order_id import OrderId
from .org_parent_name import OrgParentName
from .query_payment_data import QueryPaymentData
from .query_response_data import QueryResponseData
from .query_transaction_events import QueryTransactionEvents
from .query_transaction_payor_data import QueryTransactionPayorData
from .settlement_status import SettlementStatus
from .source import Source
from .trans_status import TransStatus
from .transaction_time import TransactionTime


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

    from payabli import (
        PaymentCategories,
        PaymentDetail,
        QueryPaymentData,
        QueryResponseData,
        QueryResponseSettlementsRecordsItem,
        QueryTransactionEvents,
        QueryTransactionPayorData,
        SplitFundingContent,
    )

    QueryResponseSettlementsRecordsItem(
        batch_amount=32.0,
        batch_number="batch-100-20-2024",
        category="auth",
        created_at=datetime.datetime.fromisoformat(
            "2024-11-19 15:58:01+00:00",
        ),
        customer=QueryTransactionPayorData(
            billing_address_1="100 Golden Ridge Drive",
            billing_address_2="STE 100",
            billing_city="Mendota",
            billing_country="US",
            billing_email="lydia@example.com",
            billing_phone="+12345678",
            billing_state="VA",
            billing_zip="20147",
            customer_id=2707,
            customer_number="901102",
            customer_status=1,
            first_name="Lydia",
            last_name="Marshall",
        ),
        expected_deposit_date=datetime.datetime.fromisoformat(
            "2024-11-22 00:00:00+00:00",
        ),
        gateway_trans_id="TRN_XXXXX",
        id=25048,
        is_hold=0,
        masked_account="1XXXXXX5678",
        method="ach",
        net_amount=2.0,
        operation="Sale",
        order_id="",
        parent_org_name="Pilgrim Planner",
        payment_data=QueryPaymentData(
            account_type="Checking",
            holder_name="Lydia Marshall",
            masked_account="1XXXXXX5678",
            payment_details=PaymentDetail(
                categories=[
                    PaymentCategories(
                        amount=1000.0,
                        label="Deposit",
                    )
                ],
                currency="USD",
                service_fee=0.0,
                split_funding=[SplitFundingContent()],
                total_amount=2.0,
            ),
        ),
        payment_trans_id="245-9e4072eef77e45979ea0e49f680000X",
        payment_trans_status=1,
        paypoint_dbaname="Gruzya Adventure Outfitters, LLC",
        paypoint_entryname="7f1a3816XX",
        paypoint_legalname="Gruzya Adventure Outfitters, LLC",
        response_data=QueryResponseData(
            authcode=" ",
            avsresponse=" ",
            avsresponse_text="",
            cvvresponse=" ",
            cvvresponse_text=" ",
            emv_auth_response_data=" ",
            response="Success",
            response_code="100",
            response_code_text="Transaction was approved.",
            responsetext="CAPTURED",
            result_code="A0000",
            result_code_text="Approved",
            transactionid="TRN_xwCAjQorWAYX1nAhAoHZVfN8iYHbI0",
        ),
        schedule_reference=0,
        settled_amount=0.5,
        settlement_date=datetime.datetime.fromisoformat(
            "2024-11-20 00:00:00+00:00",
        ),
        source="api",
        status=1,
        transaction_events=[
            QueryTransactionEvents(
                event_time=datetime.datetime.fromisoformat(
                    "2024-11-19 15:57:40+00:00",
                ),
                trans_event="Created",
            ),
            QueryTransactionEvents(
                event_data={
                    "account_id": "TRA_XXXXX",
                    "account_name": "123456",
                    "action": {
                        "app_id": "XXXXX",
                        "app_name": "PayAbli",
                        "id": "ACT_XXXXX",
                        "result_code": "SUCCESS",
                        "time_created": "2024-11-19T20:58:01.583Z",
                        "type": "AUTHORIZE",
                    },
                    "amount": "200",
                    "batch_id": "",
                    "capture_mode": "AUTO",
                    "channel": "CNP",
                    "country": "US",
                    "currency": "USD",
                    "fees": {"amount": "0", "rate": "0.00", "total_amount": "0"},
                    "id": "TRN_XXXXX",
                    "merchant_amount": "200",
                    "merchant_id": "MER_XXXXX",
                    "merchant_name": "Henriette97",
                    "order": {"reference": ""},
                    "payment_method": {
                        "bank_transfer": {
                            "account_type": "CHECKING",
                            "bank": {"name": ""},
                            "masked_account_number_last4": "XXXX5678",
                        },
                        "entry_mode": "ECOM",
                        "message": "Success",
                        "narrative": "Lydia Marshall",
                        "result": "00",
                    },
                    "reference": "245-XXXXX",
                    "status": "CAPTURED",
                    "time_created": "2024-11-19T20:58:01.583Z",
                    "type": "SALE",
                },
                event_time=datetime.datetime.fromisoformat(
                    "2024-11-19 20:58:01+00:00",
                ),
                trans_event="Approved",
            ),
            QueryTransactionEvents(
                event_time=datetime.datetime.fromisoformat(
                    "2024-11-20 03:05:10+00:00",
                ),
                trans_event="ClosedBatch",
            ),
        ],
        transaction_time=datetime.datetime.fromisoformat(
            "2024-11-19 15:58:01+00:00",
        ),
        trans_method="ach",
        type="credit",
    )
    """

    batch_amount: typing_extensions.Annotated[
        typing.Optional[float],
        FieldMetadata(alias="BatchAmount"),
        pydantic.Field(alias="BatchAmount", description="The batch amount."),
    ] = None
    batch_number: typing_extensions.Annotated[
        typing.Optional[BatchNumber], FieldMetadata(alias="BatchNumber"), pydantic.Field(alias="BatchNumber")
    ] = None
    category: typing_extensions.Annotated[
        typing.Optional[Category], FieldMetadata(alias="Category"), pydantic.Field(alias="Category")
    ] = None
    created_at: typing_extensions.Annotated[
        typing.Optional[CreatedAt], FieldMetadata(alias="CreatedAt"), pydantic.Field(alias="CreatedAt")
    ] = None
    customer: typing_extensions.Annotated[
        typing.Optional[QueryTransactionPayorData], FieldMetadata(alias="Customer"), pydantic.Field(alias="Customer")
    ] = None
    deposit_date: typing_extensions.Annotated[
        typing.Optional[DepositDate], FieldMetadata(alias="DepositDate"), pydantic.Field(alias="DepositDate")
    ] = None
    expected_deposit_date: typing_extensions.Annotated[
        typing.Optional[ExpectedDepositDate],
        FieldMetadata(alias="ExpectedDepositDate"),
        pydantic.Field(alias="ExpectedDepositDate"),
    ] = None
    external_paypoint_id: typing_extensions.Annotated[
        typing.Optional[ExternalPaypointId],
        FieldMetadata(alias="externalPaypointID"),
        pydantic.Field(alias="externalPaypointID"),
    ] = None
    gateway_trans_id: typing_extensions.Annotated[
        typing.Optional[str],
        FieldMetadata(alias="GatewayTransId"),
        pydantic.Field(alias="GatewayTransId", description="Internal identifier used for processing."),
    ] = None
    id: typing_extensions.Annotated[typing.Optional[int], FieldMetadata(alias="Id"), pydantic.Field(alias="Id")] = None
    invoice_data: typing_extensions.Annotated[
        typing.Optional[BillData], FieldMetadata(alias="invoiceData"), pydantic.Field(alias="invoiceData")
    ] = None
    is_hold: typing_extensions.Annotated[
        typing.Optional[int],
        FieldMetadata(alias="isHold"),
        pydantic.Field(
            alias="isHold",
            description="\nDescribes whether the transaction is being held or not.\n\n1 - Transaction is held\n\n0 - Transaction isn't being held",
        ),
    ] = None
    masked_account: typing_extensions.Annotated[
        typing.Optional[Maskedaccount], FieldMetadata(alias="MaskedAccount"), pydantic.Field(alias="MaskedAccount")
    ] = None
    method: typing_extensions.Annotated[
        typing.Optional[str],
        FieldMetadata(alias="Method"),
        pydantic.Field(alias="Method", description="The payment method."),
    ] = None
    net_amount: typing_extensions.Annotated[
        typing.Optional[Netamountnullable],
        FieldMetadata(alias="NetAmount"),
        pydantic.Field(alias="NetAmount", description="Net amount paid."),
    ] = None
    operation: typing_extensions.Annotated[
        typing.Optional[str],
        FieldMetadata(alias="Operation"),
        pydantic.Field(alias="Operation", description="The operation performed."),
    ] = None
    order_id: typing_extensions.Annotated[
        typing.Optional[OrderId], FieldMetadata(alias="OrderId"), pydantic.Field(alias="OrderId")
    ] = None
    parent_org_name: typing_extensions.Annotated[
        typing.Optional[OrgParentName], FieldMetadata(alias="ParentOrgName"), pydantic.Field(alias="ParentOrgName")
    ] = None
    payment_data: typing_extensions.Annotated[
        typing.Optional[QueryPaymentData], FieldMetadata(alias="PaymentData"), pydantic.Field(alias="PaymentData")
    ] = None
    payment_trans_id: typing_extensions.Annotated[
        typing.Optional[str],
        FieldMetadata(alias="PaymentTransId"),
        pydantic.Field(alias="PaymentTransId", description="The transaction ID for the payment."),
    ] = None
    payment_trans_status: typing_extensions.Annotated[
        typing.Optional[TransStatus],
        FieldMetadata(alias="PaymentTransStatus"),
        pydantic.Field(alias="PaymentTransStatus"),
    ] = None
    paypoint_dbaname: typing_extensions.Annotated[
        typing.Optional[str],
        FieldMetadata(alias="PaypointDbaname"),
        pydantic.Field(alias="PaypointDbaname", description="Paypoint DBA name."),
    ] = None
    paypoint_entryname: typing_extensions.Annotated[
        typing.Optional[str],
        FieldMetadata(alias="PaypointEntryname"),
        pydantic.Field(alias="PaypointEntryname", description="Paypoint entryname."),
    ] = None
    paypoint_legalname: typing_extensions.Annotated[
        typing.Optional[str],
        FieldMetadata(alias="PaypointLegalname"),
        pydantic.Field(alias="PaypointLegalname", description="Paypoint legal name."),
    ] = None
    response_data: typing_extensions.Annotated[
        typing.Optional[QueryResponseData], FieldMetadata(alias="ResponseData"), pydantic.Field(alias="ResponseData")
    ] = None
    schedule_reference: typing_extensions.Annotated[
        typing.Optional[int],
        FieldMetadata(alias="ScheduleReference"),
        pydantic.Field(
            alias="ScheduleReference", description="Reference to the subscription originating the transaction."
        ),
    ] = None
    settled_amount: typing_extensions.Annotated[
        typing.Optional[float],
        FieldMetadata(alias="SettledAmount"),
        pydantic.Field(alias="SettledAmount", description="The transaction amount."),
    ] = None
    settlement_date: typing_extensions.Annotated[
        typing.Optional[dt.datetime],
        FieldMetadata(alias="SettlementDate"),
        pydantic.Field(
            alias="SettlementDate",
            description="The date and time when the transaction was settled. This field is null when the transaction's `SettlementStatus` is -1, -5, or -6 (Exception, Held, or Released).",
        ),
    ] = None
    source: typing_extensions.Annotated[
        typing.Optional[Source], FieldMetadata(alias="Source"), pydantic.Field(alias="Source")
    ] = None
    status: typing_extensions.Annotated[
        typing.Optional[SettlementStatus], FieldMetadata(alias="Status"), pydantic.Field(alias="Status")
    ] = None
    transaction_events: typing_extensions.Annotated[
        typing.Optional[typing.List[QueryTransactionEvents]],
        FieldMetadata(alias="TransactionEvents"),
        pydantic.Field(alias="TransactionEvents", description="Events associated with this transaction."),
    ] = None
    transaction_time: typing_extensions.Annotated[
        typing.Optional[TransactionTime],
        FieldMetadata(alias="TransactionTime"),
        pydantic.Field(alias="TransactionTime"),
    ] = None
    trans_method: typing_extensions.Annotated[
        typing.Optional[str],
        FieldMetadata(alias="TransMethod"),
        pydantic.Field(alias="TransMethod", description="Payment method used: card or ach."),
    ] = None
    type: typing_extensions.Annotated[
        typing.Optional[str],
        FieldMetadata(alias="Type"),
        pydantic.Field(alias="Type", description="The transaction type: credit or debit."),
    ] = 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
