# 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
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 ExpandedPaymentMethod(BaseModel):
    """
    ExpandedPaymentMethod
    """ # 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, alias="accountId")
    ach_aba_code: Optional[StrictStr] = Field(default=None, alias="achAbaCode")
    ach_account_name: Optional[StrictStr] = Field(default=None, alias="achAccountName")
    ach_account_number_mask: Optional[StrictStr] = Field(default=None, alias="achAccountNumberMask")
    ach_account_type: Optional[StrictStr] = Field(default=None, alias="achAccountType")
    ach_address1: Optional[StrictStr] = Field(default=None, alias="achAddress1")
    ach_address2: Optional[StrictStr] = Field(default=None, alias="achAddress2")
    ach_bank_name: Optional[StrictStr] = Field(default=None, alias="achBankName")
    ach_city: Optional[StrictStr] = Field(default=None, alias="achCity")
    ach_country: Optional[StrictStr] = Field(default=None, alias="achCountry")
    ach_postal_code: Optional[StrictStr] = Field(default=None, alias="achPostalCode")
    ach_state: Optional[StrictStr] = Field(default=None, alias="achState")
    active: Optional[StrictBool] = None
    is_system: Optional[StrictBool] = Field(default=None, alias="isSystem")
    bank_branch_code: Optional[StrictStr] = Field(default=None, alias="bankBranchCode")
    bank_check_digit: Optional[StrictStr] = Field(default=None, alias="bankCheckDigit")
    bank_city: Optional[StrictStr] = Field(default=None, alias="bankCity")
    bank_code: Optional[StrictStr] = Field(default=None, alias="bankCode")
    bank_identification_number: Optional[StrictStr] = Field(default=None, alias="bankIdentificationNumber")
    bank_name: Optional[StrictStr] = Field(default=None, alias="bankName")
    bank_postal_code: Optional[StrictStr] = Field(default=None, alias="bankPostalCode")
    bank_street_name: Optional[StrictStr] = Field(default=None, alias="bankStreetName")
    bank_street_number: Optional[StrictStr] = Field(default=None, alias="bankStreetNumber")
    bank_transfer_account_name: Optional[StrictStr] = Field(default=None, alias="bankTransferAccountName")
    bank_transfer_account_number_mask: Optional[StrictStr] = Field(default=None, alias="bankTransferAccountNumberMask")
    bank_transfer_account_type: Optional[StrictStr] = Field(default=None, alias="bankTransferAccountType")
    bank_transfer_type: Optional[StrictStr] = Field(default=None, alias="bankTransferType")
    business_identification_code: Optional[StrictStr] = Field(default=None, alias="businessIdentificationCode")
    city: Optional[StrictStr] = None
    country: Optional[StrictStr] = None
    credit_card_address1: Optional[StrictStr] = Field(default=None, alias="creditCardAddress1")
    credit_card_address2: Optional[StrictStr] = Field(default=None, alias="creditCardAddress2")
    credit_card_city: Optional[StrictStr] = Field(default=None, alias="creditCardCity")
    credit_card_country: Optional[StrictStr] = Field(default=None, alias="creditCardCountry")
    credit_card_expiration_month: Optional[StrictInt] = Field(default=None, alias="creditCardExpirationMonth")
    credit_card_expiration_year: Optional[StrictInt] = Field(default=None, alias="creditCardExpirationYear")
    credit_card_holder_name: Optional[StrictStr] = Field(default=None, alias="creditCardHolderName")
    credit_card_mask_number: Optional[StrictStr] = Field(default=None, alias="creditCardMaskNumber")
    credit_card_postal_code: Optional[StrictStr] = Field(default=None, alias="creditCardPostalCode")
    credit_card_state: Optional[StrictStr] = Field(default=None, alias="creditCardState")
    credit_card_type: Optional[StrictStr] = Field(default=None, alias="creditCardType")
    device_session_id: Optional[StrictStr] = Field(default=None, alias="deviceSessionId")
    email: Optional[StrictStr] = None
    existing_mandate: Optional[StrictStr] = Field(default=None, alias="existingMandate")
    first_name: Optional[StrictStr] = Field(default=None, alias="firstName")
    i_ban: Optional[StrictStr] = Field(default=None, alias="iBAN")
    i_p_address: Optional[StrictStr] = Field(default=None, alias="iPAddress")
    identity_number: Optional[StrictStr] = Field(default=None, alias="identityNumber")
    company_name: Optional[StrictStr] = Field(default=None, alias="companyName")
    is_company: Optional[StrictBool] = Field(default=None, alias="isCompany")
    last_failed_sale_transaction_date: Optional[date] = Field(default=None, alias="lastFailedSaleTransactionDate")
    last_name: Optional[StrictStr] = Field(default=None, alias="lastName")
    last_transaction_date_time: Optional[StrictStr] = Field(default=None, alias="lastTransactionDateTime")
    last_transaction_status: Optional[StrictStr] = Field(default=None, alias="lastTransactionStatus")
    mandate_creation_date: Optional[date] = Field(default=None, alias="mandateCreationDate")
    mandate_id: Optional[StrictStr] = Field(default=None, alias="mandateID")
    mandate_reason: Optional[StrictStr] = Field(default=None, alias="mandateReason")
    mandate_received: Optional[StrictStr] = Field(default=None, alias="mandateReceived")
    mandate_status: Optional[StrictStr] = Field(default=None, alias="mandateStatus")
    mandate_update_date: Optional[date] = Field(default=None, alias="mandateUpdateDate")
    max_consecutive_payment_failures: Optional[StrictInt] = Field(default=None, alias="maxConsecutivePaymentFailures")
    name: Optional[StrictStr] = None
    num_consecutive_failures: Optional[StrictInt] = Field(default=None, alias="numConsecutiveFailures")
    payment_method_status: Optional[StrictStr] = Field(default=None, alias="paymentMethodStatus")
    payment_retry_window: Optional[StrictInt] = Field(default=None, alias="paymentRetryWindow")
    paypal_baid: Optional[StrictStr] = Field(default=None, alias="paypalBaid")
    paypal_email: Optional[StrictStr] = Field(default=None, alias="paypalEmail")
    paypal_preapproval_key: Optional[StrictStr] = Field(default=None, alias="paypalPreapprovalKey")
    paypal_type: Optional[StrictStr] = Field(default=None, alias="paypalType")
    phone: Optional[StrictStr] = None
    postal_code: Optional[StrictStr] = Field(default=None, alias="postalCode")
    second_token_id: Optional[StrictStr] = Field(default=None, alias="secondTokenId")
    state: Optional[StrictStr] = None
    street_name: Optional[StrictStr] = Field(default=None, alias="streetName")
    street_number: Optional[StrictStr] = Field(default=None, alias="streetNumber")
    token_id: Optional[StrictStr] = Field(default=None, alias="tokenId")
    total_number_of_error_payments: Optional[StrictInt] = Field(default=None, alias="totalNumberOfErrorPayments")
    total_number_of_processed_payments: Optional[StrictInt] = Field(default=None, alias="totalNumberOfProcessedPayments")
    type: Optional[StrictStr] = None
    use_default_retry_rule: Optional[StrictBool] = Field(default=None, alias="useDefaultRetryRule")
    id: Optional[StrictStr] = None
    created_by_id: Optional[StrictStr] = Field(default=None, alias="createdById")
    created_date: Optional[StrictStr] = Field(default=None, alias="createdDate")
    updated_by_id: Optional[StrictStr] = Field(default=None, alias="updatedById")
    updated_date: Optional[StrictStr] = Field(default=None, alias="updatedDate")
    card_brand: Optional[StrictStr] = Field(default=None, alias="cardBrand")
    card_class: Optional[StrictStr] = Field(default=None, alias="cardClass")
    card_product_type: Optional[StrictStr] = Field(default=None, alias="cardProductType")
    card_issuing_bank: Optional[StrictStr] = Field(default=None, alias="cardIssuingBank")
    card_issuing_country: Optional[StrictStr] = Field(default=None, alias="cardIssuingCountry")
    method_reference_id: Optional[StrictStr] = Field(default=None, alias="methodReferenceId")
    user_reference_id: Optional[StrictStr] = Field(default=None, alias="userReferenceId")
    sub_type: Optional[StrictStr] = Field(default=None, alias="subType")
    method_specific_data: Optional[StrictStr] = Field(default=None, alias="methodSpecificData")
    account: Optional[ExpandedAccount] = None
    additional_properties: Dict[str, Any] = {}
    __properties: ClassVar[List[str]] = ["accountId", "achAbaCode", "achAccountName", "achAccountNumberMask", "achAccountType", "achAddress1", "achAddress2", "achBankName", "achCity", "achCountry", "achPostalCode", "achState", "active", "isSystem", "bankBranchCode", "bankCheckDigit", "bankCity", "bankCode", "bankIdentificationNumber", "bankName", "bankPostalCode", "bankStreetName", "bankStreetNumber", "bankTransferAccountName", "bankTransferAccountNumberMask", "bankTransferAccountType", "bankTransferType", "businessIdentificationCode", "city", "country", "creditCardAddress1", "creditCardAddress2", "creditCardCity", "creditCardCountry", "creditCardExpirationMonth", "creditCardExpirationYear", "creditCardHolderName", "creditCardMaskNumber", "creditCardPostalCode", "creditCardState", "creditCardType", "deviceSessionId", "email", "existingMandate", "firstName", "iBAN", "iPAddress", "identityNumber", "companyName", "isCompany", "lastFailedSaleTransactionDate", "lastName", "lastTransactionDateTime", "lastTransactionStatus", "mandateCreationDate", "mandateID", "mandateReason", "mandateReceived", "mandateStatus", "mandateUpdateDate", "maxConsecutivePaymentFailures", "name", "numConsecutiveFailures", "paymentMethodStatus", "paymentRetryWindow", "paypalBaid", "paypalEmail", "paypalPreapprovalKey", "paypalType", "phone", "postalCode", "secondTokenId", "state", "streetName", "streetNumber", "tokenId", "totalNumberOfErrorPayments", "totalNumberOfProcessedPayments", "type", "useDefaultRetryRule", "id", "createdById", "createdDate", "updatedById", "updatedDate", "cardBrand", "cardClass", "cardProductType", "cardIssuingBank", "cardIssuingCountry", "methodReferenceId", "userReferenceId", "subType", "methodSpecificData", "account"]

    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 ExpandedPaymentMethod 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,
        )
        # override the default output from pydantic by calling `to_dict()` of account
        if self.account:
            _dict['account'] = self.account.to_dict()
        # 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 ExpandedPaymentMethod 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"),
            "achAddress1": obj.get("achAddress1"),
            "achAddress2": obj.get("achAddress2"),
            "achBankName": obj.get("achBankName"),
            "achCity": obj.get("achCity"),
            "achCountry": obj.get("achCountry"),
            "achPostalCode": obj.get("achPostalCode"),
            "achState": obj.get("achState"),
            "active": obj.get("active"),
            "isSystem": obj.get("isSystem"),
            "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"),
            "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"),
            "identityNumber": obj.get("identityNumber"),
            "companyName": obj.get("companyName"),
            "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"),
            "mandateReason": obj.get("mandateReason"),
            "mandateReceived": obj.get("mandateReceived"),
            "mandateStatus": obj.get("mandateStatus"),
            "mandateUpdateDate": obj.get("mandateUpdateDate"),
            "maxConsecutivePaymentFailures": obj.get("maxConsecutivePaymentFailures"),
            "name": obj.get("name"),
            "numConsecutiveFailures": obj.get("numConsecutiveFailures"),
            "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"),
            "id": obj.get("id"),
            "createdById": obj.get("createdById"),
            "createdDate": obj.get("createdDate"),
            "updatedById": obj.get("updatedById"),
            "updatedDate": obj.get("updatedDate"),
            "cardBrand": obj.get("cardBrand"),
            "cardClass": obj.get("cardClass"),
            "cardProductType": obj.get("cardProductType"),
            "cardIssuingBank": obj.get("cardIssuingBank"),
            "cardIssuingCountry": obj.get("cardIssuingCountry"),
            "methodReferenceId": obj.get("methodReferenceId"),
            "userReferenceId": obj.get("userReferenceId"),
            "subType": obj.get("subType"),
            "methodSpecificData": obj.get("methodSpecificData"),
            "account": ExpandedAccount.from_dict(obj["account"]) if obj.get("account") is not None else None
        }
        return _obj
from zuora_sdk.models.expanded_account import ExpandedAccount
# TODO: Rewrite to not use raise_errors
ExpandedPaymentMethod.model_rebuild(raise_errors=False)


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:])
