# 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 ...money_in.types.transaction_detail_customer import TransactionDetailCustomer
from ...money_in.types.transaction_detail_event import TransactionDetailEvent
from ...money_in.types.transaction_detail_invoice_data import TransactionDetailInvoiceData
from ...money_in.types.transaction_detail_payment_data import TransactionDetailPaymentData
from ...types.ach_holder_type import AchHolderType
from ...types.ach_sec_code import AchSecCode
from ...types.batch_number import BatchNumber
from ...types.chargeback_id import ChargebackId
from ...types.dbaname import Dbaname
from ...types.device import Device
from ...types.entrypage_id import EntrypageId
from ...types.entrypointfield import Entrypointfield
from ...types.external_paypoint_id import ExternalPaypointId
from ...types.external_processor_information import ExternalProcessorInformation
from ...types.fee_amount import FeeAmount
from ...types.ip_address import IpAddress
from ...types.legalname import Legalname
from ...types.operation import Operation
from ...types.order_id import OrderId
from ...types.org_parent_name import OrgParentName
from ...types.orgid import Orgid
from ...types.payor_id import PayorId
from ...types.paypoint_id import PaypointId
from ...types.pending_fee_amount import PendingFeeAmount
from ...types.query_c_fee_transaction import QueryCFeeTransaction
from ...types.refund_id import RefundId
from ...types.retrieval_id import RetrievalId
from ...types.returned_id import ReturnedId
from ...types.risk_action import RiskAction
from ...types.risk_action_code import RiskActionCode
from ...types.risk_flagged import RiskFlagged
from ...types.risk_flagged_on import RiskFlaggedOn
from ...types.risk_reason import RiskReason
from ...types.risk_status import RiskStatus
from ...types.settlement_status import SettlementStatus
from ...types.source import Source
from ...types.split_funding import SplitFunding
from ...types.trans_status import TransStatus
from .v_2_transaction_detail_response_data import V2TransactionDetailResponseData


class V2TransactionDetails(UniversalBaseModel):
    """
    Complete transaction details returned by v2 Money In endpoints. This matches the structure of the transaction details previously returned by the v1 details endpoint.

    Examples
    --------
    import datetime

    from payabli import BinData, QueryCFeeTransaction
    from payabli.money_in import (
        TransactionDetailCustomer,
        TransactionDetailEvent,
        TransactionDetailInvoiceData,
        TransactionDetailPaymentData,
        TransactionDetailPaymentDetails,
    )
    from payabli.v_2_money_in_types import (
        V2TransactionDetailResponseData,
        V2TransactionDetails,
    )

    V2TransactionDetails(
        parent_org_name="Mrinal's Pet Supplies",
        paypoint_dbaname="Mrinal's Pet Shop North",
        paypoint_legalname="Mrinal's Pet Shop North",
        paypoint_entryname="495147f647",
        payment_trans_id="3040-96dfa9a7c4ed4f82a3dd4a4a12ad28ae",
        connector_name="gp",
        external_processor_information="",
        gateway_trans_id="TRN_Ih68D6UZdip7OEQ2QFXat1yQSLF2nB",
        method="card",
        batch_number="3040_combined_20251201_3a50747d-6b5c-40ef-9f69-93a9cc7fcb49",
        batch_amount=420.0,
        payor_id=40144,
        payment_data=TransactionDetailPaymentData(
            masked_account="4XXXXXXXXXXX5439",
            account_type="visa",
            account_exp="12/25",
            holder_name="John Cassian",
            order_description="",
            bin_data=BinData(
                bin_matched_length="6",
                bin_card_brand="VISA",
                bin_card_type="CREDIT",
                bin_card_category="CLASSIC",
                bin_card_issuer="",
                bin_card_issuer_country="RUSSIAN FEDERATION",
                bin_card_issuer_country_code_a_2="RU",
                bin_card_issuer_country_number="643",
                bin_card_is_regulated="",
                bin_card_use_category="",
                bin_card_issuer_country_code_a_3="",
            ),
            payment_details=TransactionDetailPaymentDetails(
                total_amount=105.0,
                service_fee=5.0,
                check_unique_id="",
                currency="USD",
                categories=[],
                split_funding=[],
            ),
        ),
        trans_status=1,
        paypoint_id=3040,
        total_amount=105.0,
        net_amount=100.0,
        fee_amount=5.0,
        settlement_status=0,
        operation="Sale",
        response_data=V2TransactionDetailResponseData(
            result_code="A0000",
            result_code_text="Approved",
            responsetext="CAPTURED",
            authcode="AXS425",
            transactionid="TRN_Xo4dpKfmx3OxSc9svd2ccI6OOnyB2I",
            avsresponse="N",
            avsresponse_text="No Match, No address or ZIP match",
            cvvresponse="M",
            cvvresponse_text="CVV2/CVC2 match",
            response_code="100",
            response_code_text="Operation successful",
        ),
        source="api",
        schedule_reference=0,
        org_id=17448,
        refund_id=0,
        returned_id=0,
        chargeback_id=0,
        retrieval_id=0,
        invoice_data=TransactionDetailInvoiceData(),
        entrypage_id=0,
        external_paypoint_id="",
        is_validated_ach=False,
        transaction_time="2025-12-01T09:50:03.559",
        customer=TransactionDetailCustomer(
            first_name="David",
            last_name="Beckham",
            company_name="Driving School LLC",
            billing_address_1="Home Address",
            billing_address_2="",
            billing_city="",
            billing_state="",
            billing_zip="45157",
            billing_country="US",
            billing_phone="+15555555555",
            billing_email="mrinal.kundu@payabli.com",
            customer_number="C-90010",
            shipping_address_1="Home Address",
            shipping_address_2="",
            shipping_city="",
            shipping_state="",
            shipping_zip="45157",
            shipping_country="US",
            customer_id=40144,
            customer_status=0,
        ),
        cfee_transactions=[
            QueryCFeeTransaction(
                c_fee_transid="3040-96dfa9a7c4ed4f82a3dd4a4a12ad28ae",
                trans_status=1,
                fee_amount=5.0,
                settlement_status=0,
                operation="Sale",
                response_data={},
                refund_id=0,
                transaction_time=datetime.datetime.fromisoformat(
                    "2025-12-01 09:50:03.559000+00:00",
                ),
            )
        ],
        transaction_events=[
            TransactionDetailEvent(
                trans_event="Created",
                event_data="0HNHD68HATSUC:00000001",
                event_time="2025-12-01T09:50:02.558651",
            ),
            TransactionDetailEvent(
                trans_event="Approved",
                event_data="0HNHD68HATSUC:00000001",
                event_time="2025-12-01T09:50:03.609111",
            ),
        ],
        pending_fee_amount=0.0,
        risk_flagged=False,
        risk_flagged_on=datetime.datetime.fromisoformat(
            "2025-12-01 09:50:02.547000+00:00",
        ),
        risk_status="PASSED",
        risk_reason="",
        risk_action="",
        risk_action_code=0,
        device_id="",
        ach_sec_code="",
        ach_holder_type="personal",
        ip_address="255.255.255.255",
        is_same_day_ach=False,
    )
    """

    parent_org_name: typing_extensions.Annotated[
        OrgParentName, FieldMetadata(alias="parentOrgName"), pydantic.Field(alias="parentOrgName")
    ]
    paypoint_dbaname: typing_extensions.Annotated[
        Dbaname, FieldMetadata(alias="paypointDbaname"), pydantic.Field(alias="paypointDbaname")
    ]
    paypoint_legalname: typing_extensions.Annotated[
        Legalname, FieldMetadata(alias="paypointLegalname"), pydantic.Field(alias="paypointLegalname")
    ]
    paypoint_entryname: typing_extensions.Annotated[
        Entrypointfield, FieldMetadata(alias="paypointEntryname"), pydantic.Field(alias="paypointEntryname")
    ]
    payment_trans_id: typing_extensions.Annotated[
        str,
        FieldMetadata(alias="paymentTransId"),
        pydantic.Field(alias="paymentTransId", description="Unique transaction identifier."),
    ]
    connector_name: typing_extensions.Annotated[
        str,
        FieldMetadata(alias="connectorName"),
        pydantic.Field(alias="connectorName", description="Name of the payment connector used."),
    ]
    external_processor_information: typing_extensions.Annotated[
        ExternalProcessorInformation,
        FieldMetadata(alias="externalProcessorInformation"),
        pydantic.Field(alias="externalProcessorInformation"),
    ]
    gateway_trans_id: typing_extensions.Annotated[
        str,
        FieldMetadata(alias="gatewayTransId"),
        pydantic.Field(alias="gatewayTransId", description="Gateway transaction identifier."),
    ]
    order_id: typing_extensions.Annotated[
        typing.Optional[OrderId], FieldMetadata(alias="orderId"), pydantic.Field(alias="orderId")
    ] = None
    method: str = pydantic.Field()
    """
    Payment method used for the transaction.
    """

    batch_number: typing_extensions.Annotated[
        BatchNumber, FieldMetadata(alias="batchNumber"), pydantic.Field(alias="batchNumber")
    ]
    batch_amount: typing_extensions.Annotated[
        float,
        FieldMetadata(alias="batchAmount"),
        pydantic.Field(alias="batchAmount", description="Total amount in the batch."),
    ]
    payor_id: typing_extensions.Annotated[PayorId, FieldMetadata(alias="payorId"), pydantic.Field(alias="payorId")]
    payment_data: typing_extensions.Annotated[
        TransactionDetailPaymentData, FieldMetadata(alias="paymentData"), pydantic.Field(alias="paymentData")
    ]
    trans_status: typing_extensions.Annotated[
        TransStatus, FieldMetadata(alias="transStatus"), pydantic.Field(alias="transStatus")
    ]
    paypoint_id: typing_extensions.Annotated[
        PaypointId, FieldMetadata(alias="paypointId"), pydantic.Field(alias="paypointId")
    ]
    total_amount: typing_extensions.Annotated[
        float,
        FieldMetadata(alias="totalAmount"),
        pydantic.Field(alias="totalAmount", description="Total transaction amount including fees."),
    ]
    net_amount: typing_extensions.Annotated[
        float,
        FieldMetadata(alias="netAmount"),
        pydantic.Field(alias="netAmount", description="Net transaction amount excluding fees."),
    ]
    fee_amount: typing_extensions.Annotated[
        FeeAmount, FieldMetadata(alias="feeAmount"), pydantic.Field(alias="feeAmount")
    ]
    settlement_status: typing_extensions.Annotated[
        SettlementStatus, FieldMetadata(alias="settlementStatus"), pydantic.Field(alias="settlementStatus")
    ]
    operation: Operation
    response_data: typing_extensions.Annotated[
        V2TransactionDetailResponseData, FieldMetadata(alias="responseData"), pydantic.Field(alias="responseData")
    ]
    source: Source
    schedule_reference: typing_extensions.Annotated[
        int,
        FieldMetadata(alias="scheduleReference"),
        pydantic.Field(
            alias="scheduleReference", description="Reference to associated payment schedule if applicable."
        ),
    ]
    org_id: typing_extensions.Annotated[Orgid, FieldMetadata(alias="orgId"), pydantic.Field(alias="orgId")]
    refund_id: typing_extensions.Annotated[RefundId, FieldMetadata(alias="refundId"), pydantic.Field(alias="refundId")]
    returned_id: typing_extensions.Annotated[
        ReturnedId, FieldMetadata(alias="returnedId"), pydantic.Field(alias="returnedId")
    ]
    chargeback_id: typing_extensions.Annotated[
        ChargebackId, FieldMetadata(alias="chargebackId"), pydantic.Field(alias="chargebackId")
    ]
    retrieval_id: typing_extensions.Annotated[
        RetrievalId, FieldMetadata(alias="retrievalId"), pydantic.Field(alias="retrievalId")
    ]
    trans_additional_data: typing_extensions.Annotated[
        typing.Optional[typing.Any],
        FieldMetadata(alias="transAdditionalData"),
        pydantic.Field(alias="transAdditionalData"),
    ] = None
    invoice_data: typing_extensions.Annotated[
        TransactionDetailInvoiceData, FieldMetadata(alias="invoiceData"), pydantic.Field(alias="invoiceData")
    ]
    entrypage_id: typing_extensions.Annotated[
        EntrypageId, FieldMetadata(alias="entrypageId"), pydantic.Field(alias="entrypageId")
    ]
    external_paypoint_id: typing_extensions.Annotated[
        ExternalPaypointId, FieldMetadata(alias="externalPaypointID"), pydantic.Field(alias="externalPaypointID")
    ]
    is_validated_ach: typing_extensions.Annotated[
        bool,
        FieldMetadata(alias="isValidatedACH"),
        pydantic.Field(alias="isValidatedACH", description="Indicates if ACH account was validated in real-time."),
    ]
    transaction_time: typing_extensions.Annotated[
        str,
        FieldMetadata(alias="transactionTime"),
        pydantic.Field(alias="transactionTime", description="Timestamp when transaction was created."),
    ]
    customer: TransactionDetailCustomer
    split_funding_instructions: typing_extensions.Annotated[
        typing.Optional[SplitFunding],
        FieldMetadata(alias="splitFundingInstructions"),
        pydantic.Field(alias="splitFundingInstructions"),
    ] = None
    cfee_transactions: typing_extensions.Annotated[
        typing.List[QueryCFeeTransaction],
        FieldMetadata(alias="cfeeTransactions"),
        pydantic.Field(alias="cfeeTransactions"),
    ]
    transaction_events: typing_extensions.Annotated[
        typing.List[TransactionDetailEvent],
        FieldMetadata(alias="transactionEvents"),
        pydantic.Field(alias="transactionEvents"),
    ]
    pending_fee_amount: typing_extensions.Annotated[
        PendingFeeAmount, FieldMetadata(alias="pendingFeeAmount"), pydantic.Field(alias="pendingFeeAmount")
    ]
    risk_flagged: typing_extensions.Annotated[
        RiskFlagged, FieldMetadata(alias="riskFlagged"), pydantic.Field(alias="riskFlagged")
    ]
    risk_flagged_on: typing_extensions.Annotated[
        RiskFlaggedOn, FieldMetadata(alias="riskFlaggedOn"), pydantic.Field(alias="riskFlaggedOn")
    ]
    risk_status: typing_extensions.Annotated[
        RiskStatus, FieldMetadata(alias="riskStatus"), pydantic.Field(alias="riskStatus")
    ]
    risk_reason: typing_extensions.Annotated[
        RiskReason, FieldMetadata(alias="riskReason"), pydantic.Field(alias="riskReason")
    ]
    risk_action: typing_extensions.Annotated[
        RiskAction, FieldMetadata(alias="riskAction"), pydantic.Field(alias="riskAction")
    ]
    risk_action_code: typing_extensions.Annotated[
        RiskActionCode, FieldMetadata(alias="riskActionCode"), pydantic.Field(alias="riskActionCode")
    ]
    device_id: typing_extensions.Annotated[Device, FieldMetadata(alias="deviceId"), pydantic.Field(alias="deviceId")]
    ach_sec_code: typing_extensions.Annotated[
        AchSecCode, FieldMetadata(alias="achSecCode"), pydantic.Field(alias="achSecCode")
    ]
    ach_holder_type: typing_extensions.Annotated[
        AchHolderType, FieldMetadata(alias="achHolderType"), pydantic.Field(alias="achHolderType")
    ]
    ip_address: typing_extensions.Annotated[
        IpAddress, FieldMetadata(alias="ipAddress"), pydantic.Field(alias="ipAddress")
    ]
    is_same_day_ach: typing_extensions.Annotated[
        bool,
        FieldMetadata(alias="isSameDayACH"),
        pydantic.Field(alias="isSameDayACH", description="Indicates if ACH transaction uses same-day processing."),
    ]
    wallet_type: typing_extensions.Annotated[
        typing.Optional[str],
        FieldMetadata(alias="walletType"),
        pydantic.Field(alias="walletType", description="Digital wallet type if applicable."),
    ] = 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
