# coding: utf-8

"""
    Zuora API Reference

    REST API reference for the Zuora Billing, Payments, and Central Platform! Check out the [REST API Overview](https://www.zuora.com/developer/api-references/api/overview/).

    The version of the OpenAPI document: 2024-05-20
    Contact: docs@zuora.com
    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""  # noqa: E501


from __future__ import annotations
import pprint
import re  # noqa: F401
import json

from pydantic import field_validator
from datetime import date, datetime
from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from typing import Optional, Set
from typing_extensions import Self

class PaymentMethodSnapshotResponse(BaseModel):
    """
    PaymentMethodSnapshotResponse
    """ # noqa: E501
    # avoid validation
    def __init__(self, **kwargs):
        # Directly assign values without validation using `construct()`
        model = self.construct(**kwargs)
        self.__dict__.update(model.__dict__)

        _dict_all = convert_snake_dict_to_camel(kwargs, self.model_fields, self.__properties)

        _dict = self.to_alias_dict(_dict_all)
        for field_name, field_info in self.model_fields.items():
            alias = field_info.alias or field_name
            if alias in _dict:
                self.__dict__[field_name] = _dict.get(alias)
        self.update_additional_properties(self, _dict_all)
        pass

    def __setattr__(self, name, value):
        # Override setattr to bypass validation when setting attributes
        object.__setattr__(self, name, value)

    account_id: Optional[StrictStr] = Field(default=None, description="The ID of the customer account associated with this payment method.", alias="AccountId")
    ach_aba_code: Optional[StrictStr] = Field(default=None, description="The nine-digit routing number or ABA number used by banks. Applicable to ACH payment methods.", alias="AchAbaCode")
    ach_account_name: Optional[StrictStr] = Field(default=None, description="The name of the account holder, which can be either a person or a company. Applicable to ACH payment methods.", alias="AchAccountName")
    ach_account_number_mask: Optional[StrictStr] = Field(default=None, description="This is a masked displayable version of the ACH account number, used for security purposes. For example: `XXXXXXXXX54321`.", alias="AchAccountNumberMask")
    ach_account_type: Optional[StrictStr] = Field(default=None, alias="AchAccountType")
    ach_bank_name: Optional[StrictStr] = Field(default=None, description="The name of the bank where the ACH payment account is held.", alias="AchBankName")
    bank_branch_code: Optional[StrictStr] = Field(default=None, description="The branch code of the bank used for direct debit.", alias="BankBranchCode")
    bank_check_digit: Optional[StrictStr] = Field(default=None, description="The check digit in the international bank account number, which confirms the validity of the account. Applicable to direct debit payment methods.", alias="BankCheckDigit")
    bank_city: Optional[StrictStr] = Field(default=None, description="The city of the direct debit bank.", alias="BankCity")
    bank_code: Optional[StrictStr] = Field(default=None, description="The sort code or number that identifies the bank. This is also known as the sort code.", alias="BankCode")
    bank_identification_number: Optional[StrictStr] = Field(default=None, description="The first six or eight digits of the payment method's number, such as the credit card number or account number. Banks use this number to identify a payment method.", alias="BankIdentificationNumber")
    bank_name: Optional[StrictStr] = Field(default=None, description="The name of the direct debit bank.", alias="BankName")
    bank_postal_code: Optional[StrictStr] = Field(default=None, description="The zip code or postal code of the direct debit bank.", alias="BankPostalCode")
    bank_street_name: Optional[StrictStr] = Field(default=None, description="The name of the street of the direct debit bank.", alias="BankStreetName")
    bank_street_number: Optional[StrictStr] = Field(default=None, description="The number of the direct debit bank.", alias="BankStreetNumber")
    bank_transfer_account_name: Optional[StrictStr] = Field(default=None, description="The name on the direct debit bank account.", alias="BankTransferAccountName")
    bank_transfer_account_number_mask: Optional[StrictStr] = Field(default=None, description="This is a masked displayable version of the bank account number, used for security purposes. For example: `XXXXXXXXX54321`.", alias="BankTransferAccountNumberMask")
    bank_transfer_account_type: Optional[StrictStr] = Field(default=None, description="The type of the customer's bank account. Applicable to direct debit payment methods.", alias="BankTransferAccountType")
    bank_transfer_type: Optional[StrictStr] = Field(default=None, alias="BankTransferType")
    business_identification_code: Optional[StrictStr] = Field(default=None, description="The business identification code for Swiss direct payment methods that use the Global Collect payment gateway. Only applicable to direct debit payments in Switzerland with Global Collect.", alias="BusinessIdentificationCode")
    city: Optional[StrictStr] = Field(default=None, description="The city of the customer's address. Applicable to debit payment methods.", alias="City")
    company_name: Optional[StrictStr] = Field(default=None, description="The name of the company. ", alias="CompanyName")
    country: Optional[StrictStr] = Field(default=None, description="The two-letter country code of the customer's address. Applicable to direct debit payment methods.", alias="Country")
    credit_card_address1: Optional[StrictStr] = Field(default=None, description="The first line of the card holder's address, which is often a street address or business name. Applicable to credit card and direct debit payment methods.", alias="CreditCardAddress1")
    credit_card_address2: Optional[StrictStr] = Field(default=None, description="The second line of the card holder's address. Applicable to credit card and direct debit payment methods.", alias="CreditCardAddress2")
    credit_card_city: Optional[StrictStr] = Field(default=None, description="The city of the card holder's address. Applicable to credit card and direct debit payment methods.", alias="CreditCardCity")
    credit_card_country: Optional[StrictStr] = Field(default=None, description="The country of the card holder's address.", alias="CreditCardCountry")
    credit_card_expiration_month: Optional[StrictInt] = Field(default=None, description="The expiration month of the credit card or debit card. Applicable to credit card and direct debit payment methods.", alias="CreditCardExpirationMonth")
    credit_card_expiration_year: Optional[StrictInt] = Field(default=None, description="The expiration month of the credit card or debit card. Applicable to credit card and direct debit payment methods.", alias="CreditCardExpirationYear")
    credit_card_holder_name: Optional[StrictStr] = Field(default=None, description="The full name of the card holder. Applicable to credit card and direct debit payment methods.", alias="CreditCardHolderName")
    credit_card_mask_number: Optional[StrictStr] = Field(default=None, description="A masked version of the credit or debit card number.", alias="CreditCardMaskNumber")
    credit_card_postal_code: Optional[StrictStr] = Field(default=None, description="The billing address's zip code.", alias="CreditCardPostalCode")
    credit_card_state: Optional[StrictStr] = Field(default=None, description="The billing address's state. Applicable if `CreditCardCountry` is either Canada or the US.", alias="CreditCardState")
    credit_card_type: Optional[StrictStr] = Field(default=None, alias="CreditCardType")
    device_session_id: Optional[StrictStr] = Field(default=None, description="The session ID of the user when the `PaymentMethod` was created or updated.", alias="DeviceSessionId")
    email: Optional[StrictStr] = Field(default=None, description="An email address for the payment method in addition to the bill to contact email address.", alias="Email")
    existing_mandate: Optional[StrictStr] = Field(default=None, alias="ExistingMandate")
    first_name: Optional[StrictStr] = Field(default=None, description="The customer's first name. Only applicable to direct debit payment methods.", alias="FirstName")
    iban: Optional[StrictStr] = Field(default=None, description="The International Bank Account Number. Only applicable to direct debit payment methods.", alias="IBAN")
    ip_address: Optional[StrictStr] = Field(default=None, description="The IP address of the user when the payment method was created or updated.", alias="IPAddress")
    id: Optional[StrictStr] = Field(default=None, description="Object identifier.", alias="Id")
    identity_number: Optional[StrictStr] = Field(default=None, description="The unique identity number of the customer account.  ", alias="IdentityNumber")
    is_company: Optional[StrictBool] = Field(default=None, description="Whether the customer account is a company. ", alias="IsCompany")
    last_failed_sale_transaction_date: Optional[datetime] = Field(default=None, description="The date of the last failed attempt to collect payment with this payment method.", alias="LastFailedSaleTransactionDate")
    last_name: Optional[StrictStr] = Field(default=None, description="The customer's last name. Only applicable to direct debit payment methods.", alias="LastName")
    last_transaction_date_time: Optional[datetime] = Field(default=None, description="The date of the most recent transaction.", alias="LastTransactionDateTime")
    last_transaction_status: Optional[StrictStr] = Field(default=None, description="The status of the most recent transaction.", alias="LastTransactionStatus")
    mandate_creation_date: Optional[date] = Field(default=None, description="The date when the mandate was created, in `yyyy-mm-dd` format. A mandate is a signed authorization for UK and NL customers. Only applicable to direct debit payment methods.", alias="MandateCreationDate")
    mandate_id: Optional[StrictStr] = Field(default=None, description="The ID of the mandate. A mandate is a signed authorization for UK and NL customers. Only applicable to direct debit payment methods.", alias="MandateID")
    mandate_received: Optional[StrictStr] = Field(default=None, description="Indicates if  the mandate was received. A mandate is a signed authorization for UK and NL customers. Only applicable to direct debit payment methods.", alias="MandateReceived")
    mandate_update_date: Optional[date] = Field(default=None, description="The date when the mandate was last updated, in `yyyy-mm-dd` format. A mandate is a signed authorization for UK and NL customers. Only applicable to direct debit payment methods.", alias="MandateUpdateDate")
    max_consecutive_payment_failures: Optional[StrictInt] = Field(default=None, description="The number of allowable consecutive failures Zuora attempts with the payment method before stopping.", alias="MaxConsecutivePaymentFailures")
    name: Optional[StrictStr] = Field(default=None, description="The name of the payment method.", alias="Name")
    num_consecutive_failures: Optional[StrictInt] = Field(default=None, description="The number of consecutive failed payment for the payment method.", alias="NumConsecutiveFailures")
    payment_method_id: Optional[StrictStr] = Field(default=None, description="Object identifier of the payment method.", alias="PaymentMethodId")
    payment_method_status: Optional[StrictStr] = Field(default=None, alias="PaymentMethodStatus")
    payment_retry_window: Optional[StrictInt] = Field(default=None, description="The retry interval setting, which prevents making a payment attempt if the last failed attempt was within the last specified number of hours.", alias="PaymentRetryWindow")
    paypal_baid: Optional[StrictStr] = Field(default=None, description="The PayPal billing agreement ID, which is a contract between two PayPal accounts.", alias="PaypalBaid")
    paypal_email: Optional[StrictStr] = Field(default=None, description="The email address associated with the account holder's PayPal account or of the PayPal account of the person paying for the service.", alias="PaypalEmail")
    paypal_preapproval_key: Optional[StrictStr] = Field(default=None, description="PayPal's Adaptive Payments API key.", alias="PaypalPreapprovalKey")
    paypal_type: Optional[StrictStr] = Field(default=None, alias="PaypalType")
    phone: Optional[StrictStr] = Field(default=None, description="The phone number that the account holder registered with the bank. This field is used for credit card validation when passing to a gateway.", alias="Phone")
    postal_code: Optional[StrictStr] = Field(default=None, description="The zip code of the customer's address. Only applicable to direct debit payment methods.", alias="PostalCode")
    second_token_id: Optional[StrictStr] = Field(default=None, description="A gateway unique identifier that replaces sensitive payment method data. Applicable to CC Reference Transaction payment methods.", alias="SecondTokenId")
    state: Optional[StrictStr] = Field(default=None, description="The state of the customer's address. Only applicable to direct debit payment methods.", alias="State")
    street_name: Optional[StrictStr] = Field(default=None, description="The street name of the customer's address. Only applicable to direct debit payment methods.", alias="StreetName")
    street_number: Optional[StrictStr] = Field(default=None, description="The street number of the customer's address. Only applicable to direct debit payment methods.", alias="StreetNumber")
    token_id: Optional[StrictStr] = Field(default=None, description="A gateway unique identifier that replaces sensitive payment method data or represents a gateway's unique customer profile. Applicable to CC Reference Transaction payment methods.", alias="TokenId")
    total_number_of_error_payments: Optional[StrictInt] = Field(default=None, description="The number of error payments that used this payment method.", alias="TotalNumberOfErrorPayments")
    total_number_of_processed_payments: Optional[StrictInt] = Field(default=None, description="The number of successful payments that used this payment method.", alias="TotalNumberOfProcessedPayments")
    type: Optional[StrictStr] = Field(default=None, alias="Type")
    use_default_retry_rule: Optional[StrictBool] = Field(default=None, description="Determines whether to use the default retry rules configured in the Zuora Payments settings.", alias="UseDefaultRetryRule")
    additional_properties: Dict[str, Any] = {}
    __properties: ClassVar[List[str]] = ["AccountId", "AchAbaCode", "AchAccountName", "AchAccountNumberMask", "AchAccountType", "AchBankName", "BankBranchCode", "BankCheckDigit", "BankCity", "BankCode", "BankIdentificationNumber", "BankName", "BankPostalCode", "BankStreetName", "BankStreetNumber", "BankTransferAccountName", "BankTransferAccountNumberMask", "BankTransferAccountType", "BankTransferType", "BusinessIdentificationCode", "City", "CompanyName", "Country", "CreditCardAddress1", "CreditCardAddress2", "CreditCardCity", "CreditCardCountry", "CreditCardExpirationMonth", "CreditCardExpirationYear", "CreditCardHolderName", "CreditCardMaskNumber", "CreditCardPostalCode", "CreditCardState", "CreditCardType", "DeviceSessionId", "Email", "ExistingMandate", "FirstName", "IBAN", "IPAddress", "Id", "IdentityNumber", "IsCompany", "LastFailedSaleTransactionDate", "LastName", "LastTransactionDateTime", "LastTransactionStatus", "MandateCreationDate", "MandateID", "MandateReceived", "MandateUpdateDate", "MaxConsecutivePaymentFailures", "Name", "NumConsecutiveFailures", "PaymentMethodId", "PaymentMethodStatus", "PaymentRetryWindow", "PaypalBaid", "PaypalEmail", "PaypalPreapprovalKey", "PaypalType", "Phone", "PostalCode", "SecondTokenId", "State", "StreetName", "StreetNumber", "TokenId", "TotalNumberOfErrorPayments", "TotalNumberOfProcessedPayments", "Type", "UseDefaultRetryRule"]

    model_config = ConfigDict(
        populate_by_name=True,
        validate_assignment=True,
        protected_namespaces=(),
    )


    def to_str(self) -> str:
        """Returns the string representation of the model using alias"""
        return pprint.pformat(self.model_dump(by_alias=True))

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
        return json.dumps(self.to_dict())

    @classmethod
    def from_json(cls, json_str: str) -> Optional[Self]:
        """Create an instance of PaymentMethodSnapshotResponse from a JSON string"""
        return cls.from_dict(json.loads(json_str))

    def to_dict(self) -> Dict[str, Any]:
        """Return the dictionary representation of the model using alias.

        This has the following differences from calling pydantic's
        `self.model_dump(by_alias=True)`:

        * `None` is only added to the output dict for nullable fields that
          were set at model initialization. Other fields with value `None`
          are ignored.
        * Fields in `self.additional_properties` are added to the output dict.
        """
        excluded_fields: Set[str] = set([
            "additional_properties",
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # puts key-value pairs in additional_properties in the top level
        if self.additional_properties is not None:
            for _key, _value in self.additional_properties.items():
                _dict[_key] = _value

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of PaymentMethodSnapshotResponse from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return cls.model_validate(obj)

        obj = convert_snake_dict_to_camel(obj, cls.model_fields, cls.__properties)

        _obj = cls.model_validate(cls.to_alias_dict(obj))
        return cls.update_additional_properties(_obj, obj)

    @classmethod
    def update_additional_properties(cls, obj, _dict: Optional[Dict[str, Any]]):
        # store additional fields in additional_properties

        # store additional fields in additional_properties
        for _key in _dict.keys():
            if _key not in cls.__properties:
                obj.additional_properties[_key] = _dict.get(_key)


        return obj
        pass

    @classmethod
    def to_alias_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Dict[str, Any]]:

        if not isinstance(obj, dict):
            return cls.model_validate(obj)

        return {
            "AccountId": obj.get("AccountId"),
            "AchAbaCode": obj.get("AchAbaCode"),
            "AchAccountName": obj.get("AchAccountName"),
            "AchAccountNumberMask": obj.get("AchAccountNumberMask"),
            "AchAccountType": obj.get("AchAccountType"),
            "AchBankName": obj.get("AchBankName"),
            "BankBranchCode": obj.get("BankBranchCode"),
            "BankCheckDigit": obj.get("BankCheckDigit"),
            "BankCity": obj.get("BankCity"),
            "BankCode": obj.get("BankCode"),
            "BankIdentificationNumber": obj.get("BankIdentificationNumber"),
            "BankName": obj.get("BankName"),
            "BankPostalCode": obj.get("BankPostalCode"),
            "BankStreetName": obj.get("BankStreetName"),
            "BankStreetNumber": obj.get("BankStreetNumber"),
            "BankTransferAccountName": obj.get("BankTransferAccountName"),
            "BankTransferAccountNumberMask": obj.get("BankTransferAccountNumberMask"),
            "BankTransferAccountType": obj.get("BankTransferAccountType"),
            "BankTransferType": obj.get("BankTransferType"),
            "BusinessIdentificationCode": obj.get("BusinessIdentificationCode"),
            "City": obj.get("City"),
            "CompanyName": obj.get("CompanyName"),
            "Country": obj.get("Country"),
            "CreditCardAddress1": obj.get("CreditCardAddress1"),
            "CreditCardAddress2": obj.get("CreditCardAddress2"),
            "CreditCardCity": obj.get("CreditCardCity"),
            "CreditCardCountry": obj.get("CreditCardCountry"),
            "CreditCardExpirationMonth": obj.get("CreditCardExpirationMonth"),
            "CreditCardExpirationYear": obj.get("CreditCardExpirationYear"),
            "CreditCardHolderName": obj.get("CreditCardHolderName"),
            "CreditCardMaskNumber": obj.get("CreditCardMaskNumber"),
            "CreditCardPostalCode": obj.get("CreditCardPostalCode"),
            "CreditCardState": obj.get("CreditCardState"),
            "CreditCardType": obj.get("CreditCardType"),
            "DeviceSessionId": obj.get("DeviceSessionId"),
            "Email": obj.get("Email"),
            "ExistingMandate": obj.get("ExistingMandate"),
            "FirstName": obj.get("FirstName"),
            "IBAN": obj.get("IBAN"),
            "IPAddress": obj.get("IPAddress"),
            "Id": obj.get("Id"),
            "IdentityNumber": obj.get("IdentityNumber"),
            "IsCompany": obj.get("IsCompany"),
            "LastFailedSaleTransactionDate": obj.get("LastFailedSaleTransactionDate"),
            "LastName": obj.get("LastName"),
            "LastTransactionDateTime": obj.get("LastTransactionDateTime"),
            "LastTransactionStatus": obj.get("LastTransactionStatus"),
            "MandateCreationDate": obj.get("MandateCreationDate"),
            "MandateID": obj.get("MandateID"),
            "MandateReceived": obj.get("MandateReceived"),
            "MandateUpdateDate": obj.get("MandateUpdateDate"),
            "MaxConsecutivePaymentFailures": obj.get("MaxConsecutivePaymentFailures"),
            "Name": obj.get("Name"),
            "NumConsecutiveFailures": obj.get("NumConsecutiveFailures"),
            "PaymentMethodId": obj.get("PaymentMethodId"),
            "PaymentMethodStatus": obj.get("PaymentMethodStatus"),
            "PaymentRetryWindow": obj.get("PaymentRetryWindow"),
            "PaypalBaid": obj.get("PaypalBaid"),
            "PaypalEmail": obj.get("PaypalEmail"),
            "PaypalPreapprovalKey": obj.get("PaypalPreapprovalKey"),
            "PaypalType": obj.get("PaypalType"),
            "Phone": obj.get("Phone"),
            "PostalCode": obj.get("PostalCode"),
            "SecondTokenId": obj.get("SecondTokenId"),
            "State": obj.get("State"),
            "StreetName": obj.get("StreetName"),
            "StreetNumber": obj.get("StreetNumber"),
            "TokenId": obj.get("TokenId"),
            "TotalNumberOfErrorPayments": obj.get("TotalNumberOfErrorPayments"),
            "TotalNumberOfProcessedPayments": obj.get("TotalNumberOfProcessedPayments"),
            "Type": obj.get("Type"),
            "UseDefaultRetryRule": obj.get("UseDefaultRetryRule")
        }
        return _obj


def convert_snake_dict_to_camel(_dict: dict, model_fields, properties):
    if not isinstance(_dict, dict):
        return _dict
    new_dict = {}
    for k, v in _dict.items():
        if k in model_fields:
            # model_fields: key is attribute name like bill_to_contact,
            alias = model_fields.get(k).alias or k
            new_dict[alias] = v
            pass
        else:
            new_key = snake_to_camel(k)
            if properties is not None and isinstance(properties, list) and new_key in properties:
                new_dict[new_key] = v
            else:
                new_dict[k] = v
    return new_dict
    pass


def snake_to_camel(name):
    if name is None or '_' not in name:
        return name
    components = name.split('_')
    return components[0] + ''.join(x.title() for x in components[1:])
