"""paypalserversdk.

This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ).
"""

# ruff: noqa: E501

class StoredPaymentSourceUsageType(object):
    """Implementation of the 'Stored Payment Source Usage Type' enum.

    Indicates if this is a `first` or `subsequent` payment using a stored payment
    source (also referred to as stored credential or card on file).

    Attributes:
        FIRST: Indicates the Initial/First payment with a payment_source that is
            intended to be stored upon successful processing of the payment.
        SUBSEQUENT: Indicates a payment using a stored payment_source which has been
            successfully used previously for a payment.
        DERIVED: Indicates that PayPal will derive the value of `FIRST` or
            `SUBSEQUENT` based on data available to PayPal.

    """

    FIRST = "FIRST"

    SUBSEQUENT = "SUBSEQUENT"

    DERIVED = "DERIVED"

    @classmethod
    def from_value(cls, value, default=None):
        """Return the matching enum value for the given input."""
        if value is None:
            return default

        # If numeric and matches directly
        if isinstance(value, int):
            for name, val in cls.__dict__.items():
                if not name.startswith("_") and val == value:
                    return val

        # If string, perform case-insensitive match
        if isinstance(value, str):
            value_lower = value.lower()
            for name, val in cls.__dict__.items():
                if not name.startswith("_") and (
                    name.lower() == value_lower or str(val).lower() == value_lower
                ):
                    return val

        # Fallback to default
        return default
