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

import typing

import pydantic
from ...core.pydantic_utilities import IS_PYDANTIC_V2, UniversalBaseModel
from .v_2_response_action import V2ResponseAction
from .v_2_response_code import V2ResponseCode
from .v_2_response_explanation import V2ResponseExplanation
from .v_2_response_reason import V2ResponseReason
from .v_2_transaction_details import V2TransactionDetails


class V2DeclinedTransactionResponseWrapper(UniversalBaseModel):
    """
    Response wrapper for declined v2 Money In transaction endpoints (HTTP 402). Returned when a transaction is declined by the card network or issuer. All decline responses use this format with unified response codes starting with 'D'. The `data` field contains transaction details.

    Examples
    --------
    import datetime

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

    V2DeclinedTransactionResponseWrapper(
        code="D0100",
        reason="Declined",
        explanation="Generic decline from card network or card issuer",
        action="Use different card or payment method",
        data=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",
            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=3,
            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="D0100",
                result_code_text="Declined",
                responsetext="DECLINE",
                transactionid="TRN_Ih68D6UZdip7OEQ2QFXat1yQSLF2nB",
                response_code="200",
                response_code_text="Do not honor",
            ),
            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="david.beckham@example.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=[],
            transaction_events=[
                TransactionDetailEvent(
                    trans_event="Created",
                    event_data="0HNHD68HATSUC:00000001",
                    event_time="2025-12-01T09:50:02.558651",
                ),
                TransactionDetailEvent(
                    trans_event="Declined",
                    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,
        ),
    )
    """

    code: V2ResponseCode
    reason: V2ResponseReason
    explanation: V2ResponseExplanation
    action: V2ResponseAction
    data: V2TransactionDetails
    token: typing.Optional[str] = pydantic.Field(default=None)
    """
    Pagination token (equivalent to `pageIdentifier` in v1 APIs). Returns `null` when pagination is not applicable.
    """

    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
