# 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 .accounttype import Accounttype
from .charge_back_response import ChargeBackResponse
from .created_at import CreatedAt
from .dbaname import Dbaname
from .entrypointfield import Entrypointfield
from .legalname import Legalname
from .netamountnullable import Netamountnullable
from .order_id import OrderId
from .org_parent_name import OrgParentName
from .query_payment_data import QueryPaymentData
from .query_transaction_payor_data import QueryTransactionPayorData
from .transaction_query_records import TransactionQueryRecords
from .transaction_time import TransactionTime


class ChargebackQueryRecords(UniversalBaseModel):
    account_type: typing_extensions.Annotated[typing.Optional[Accounttype], FieldMetadata(alias="accountType")] = None
    case_number: typing_extensions.Annotated[typing.Optional[str], FieldMetadata(alias="caseNumber")] = pydantic.Field(
        default=None
    )
    """
    Number of case assigned to the chargeback.
    """

    chargeback_date: typing_extensions.Annotated[
        typing.Optional[dt.datetime], FieldMetadata(alias="chargebackDate")
    ] = pydantic.Field(default=None)
    """
    Date of chargeback in format YYYY-MM-DD or MM/DD/YYYY.
    """

    created_at: typing_extensions.Annotated[typing.Optional[CreatedAt], FieldMetadata(alias="createdAt")] = (
        pydantic.Field(default=None)
    )
    """
    Timestamp when the register was created, in UTC.
    """

    customer: typing.Optional[QueryTransactionPayorData] = None
    id: typing.Optional[int] = pydantic.Field(default=None)
    """
    Identifier of chargeback or return.
    """

    last_four: typing_extensions.Annotated[str, FieldMetadata(alias="lastFour")] = pydantic.Field()
    """
    Last 4 digits of card or bank account involved in chargeback or return.
    """

    method: str = pydantic.Field()
    """
    Type of payment vehicle: **ach** or **card**.
    """

    net_amount: typing_extensions.Annotated[typing.Optional[Netamountnullable], FieldMetadata(alias="netAmount")] = (
        pydantic.Field(default=None)
    )
    """
    Net amount in chargeback or ACH return.
    """

    order_id: typing_extensions.Annotated[typing.Optional[OrderId], FieldMetadata(alias="orderId")] = None
    parent_org_name: typing_extensions.Annotated[
        typing.Optional[OrgParentName], FieldMetadata(alias="parentOrgName")
    ] = None
    payment_data: typing_extensions.Annotated[typing.Optional[QueryPaymentData], FieldMetadata(alias="paymentData")] = (
        None
    )
    payment_id: typing_extensions.Annotated[typing.Optional[str], FieldMetadata(alias="PaymentId")] = pydantic.Field(
        default=None
    )
    """
    ReferenceId of the transaction in Payabli.
    """

    paypoint_dbaname: typing_extensions.Annotated[typing.Optional[Dbaname], FieldMetadata(alias="paypointDbaname")] = (
        pydantic.Field(default=None)
    )
    """
    The paypoint's DBA name.
    """

    paypoint_entryname: typing_extensions.Annotated[
        typing.Optional[Entrypointfield], FieldMetadata(alias="paypointEntryname")
    ] = pydantic.Field(default=None)
    """
    The paypoint's entryname.
    """

    paypoint_legalname: typing_extensions.Annotated[
        typing.Optional[Legalname], FieldMetadata(alias="paypointLegalname")
    ] = pydantic.Field(default=None)
    """
    The paypoint's legal name.
    """

    reason: typing.Optional[str] = pydantic.Field(default=None)
    """
    Text describing the chargeback or ACH return reason.
    """

    reason_code: typing_extensions.Annotated[typing.Optional[str], FieldMetadata(alias="reasonCode")] = pydantic.Field(
        default=None
    )
    """
    R code for returned ACH or custom code identifying the reason.
    """

    reference_number: typing_extensions.Annotated[typing.Optional[str], FieldMetadata(alias="referenceNumber")] = (
        pydantic.Field(default=None)
    )
    """
    Processor reference number to the chargeback.
    """

    responses: typing.Optional[typing.List[ChargeBackResponse]] = pydantic.Field(default=None)
    """
    Chargeback response records.
    """

    status: typing.Optional[int] = pydantic.Field(default=None)
    """
    Status for chargeback or ACH return
    
    - 0: Open (chargebacks only)
    - 1: Pending (chargebacks only)
    - 2: Closed-Won (chargebacks only)
    - 3: Closed-Lost (chargebacks only)
    - 4: ACH Return (ACH only)
    - 5: ACH Dispute, Not Authorized (ACH only)
    """

    transaction: typing.Optional[TransactionQueryRecords] = None
    transaction_time: typing_extensions.Annotated[
        typing.Optional[TransactionTime], FieldMetadata(alias="transactionTime")
    ] = 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
