# 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 .initiator import Initiator
from .pay_method_stored_method_method import PayMethodStoredMethodMethod
from .stored_method_usage_type import StoredMethodUsageType
from .storedmethodid import Storedmethodid


class PayMethodStoredMethod(UniversalBaseModel):
    """
    The required and recommended fields for a payment made with a stored payment method.
    """

    initiator: typing.Optional[Initiator] = None
    method: PayMethodStoredMethodMethod = pydantic.Field()
    """
    Method to use for the transaction. Use either `card` or `ach`, depending on what kind of method was tokenized to use a saved payment method for this transaction.
    """

    stored_method_id: typing_extensions.Annotated[
        typing.Optional[Storedmethodid], FieldMetadata(alias="storedMethodId")
    ] = pydantic.Field(default=None)
    """
    Payabli identifier of a tokenized payment method.
    """

    stored_method_usage_type: typing_extensions.Annotated[
        typing.Optional[StoredMethodUsageType], FieldMetadata(alias="storedMethodUsageType")
    ] = 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
