"""cellpointapi.

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

# ruff: noqa: E501
from cellpointapi.api_helper import APIHelper
from cellpointapi.models.card_instrument_card_node import (
    CardInstrumentCardNode,
)
from cellpointapi.models.payment_method import (
    PaymentMethod,
)
from cellpointapi.models.phone import Phone
from cellpointapi.models.postal_address import (
    PostalAddress,
)


class CardPaymentInstrument(object):
    """Implementation of the 'CardPaymentInstrument' model.

    The card payment instrument.

    Attributes:
        method (PaymentMethod): Payment method type.
        card (CardInstrumentCardNode): Card that was used in the payment.
        billing_address (PostalAddress): A mailing address.
        phone (Phone): Telephone number.
        additional_properties (Dict[str, Any]): The additional properties for the
            model.

    """

    # Create a mapping from Model property names to API property names
    _names = {
        "method": "method",
        "card": "card",
        "billing_address": "billingAddress",
        "phone": "phone",
    }

    def __init__(
        self,
        method=None,
        card=None,
        billing_address=None,
        phone=None,
        additional_properties=None):
        """Initialize a CardPaymentInstrument instance."""
        # Initialize members of the class
        self.method = method
        self.card = card
        self.billing_address = billing_address
        self.phone = phone

        # Add additional model properties to the instance
        if additional_properties is None:
            additional_properties = {}
        self.additional_properties = additional_properties

    @classmethod
    def from_dictionary(cls,
                        dictionary):
        """Create an instance of this model from a dictionary

        Args:
            dictionary (dictionary): A dictionary representation of the object
            as obtained from the deserialization of the server's response. The
            keys MUST match property names in the API description.

        Returns:
            object: An instance of this structure class.

        """
        if not isinstance(dictionary, dict) or dictionary is None:
            return None

        # Extract variables from the dictionary
        method =\
            dictionary.get("method")\
            if dictionary.get("method")\
                else None
        card =\
            CardInstrumentCardNode.from_dictionary(
                dictionary.get("card"))\
                if dictionary.get("card") else None
        billing_address =\
            PostalAddress.from_dictionary(
                dictionary.get("billingAddress"))\
                if dictionary.get("billingAddress") else None
        phone =\
            Phone.from_dictionary(
                dictionary.get("phone"))\
                if dictionary.get("phone") else None

        additional_properties = APIHelper.get_additional_properties(
            dictionary={k: v for k, v in dictionary.items()
                        if k not in cls._names.values()},
            unboxing_function=lambda value: value)

        # Return an object of this model
        return cls(method,
                   card,
                   billing_address,
                   phone,
                   additional_properties)

    @classmethod
    def validate(cls, dictionary):
        """Validate dictionary against class required properties

        Args:
            dictionary (dictionary): A dictionary representation of the object
            as obtained from the deserialization of the server's response. The
            keys MUST match property names in the API description.

        Returns:
            boolean : if dictionary is valid contains required properties.

        """
        if isinstance(dictionary, cls):
            return APIHelper.is_valid_type(
                    value=dictionary.method,
                    type_callable=lambda value:
                        PaymentMethod.validate(value)) \
                and APIHelper.is_valid_type(
                    value=dictionary.card,
                    type_callable=lambda value:
                        CardInstrumentCardNode.validate(value),
                    is_model_dict=True) \
                and APIHelper.is_valid_type(
                    value=dictionary.billing_address,
                    type_callable=lambda value:
                        PostalAddress.validate(value),
                    is_model_dict=True) \
                and APIHelper.is_valid_type(
                    value=dictionary.phone,
                    type_callable=lambda value:
                        Phone.validate(value),
                    is_model_dict=True)

        if not isinstance(dictionary, dict):
            return False

        return APIHelper.is_valid_type(
                value=dictionary.get("method"),
                type_callable=lambda value:
                    PaymentMethod.validate(value)) \
            and APIHelper.is_valid_type(
                value=dictionary.get("card"),
                type_callable=lambda value:
                    CardInstrumentCardNode.validate(value),
                is_model_dict=True) \
            and APIHelper.is_valid_type(
                value=dictionary.get("billingAddress"),
                type_callable=lambda value:
                    PostalAddress.validate(value),
                is_model_dict=True) \
            and APIHelper.is_valid_type(
                value=dictionary.get("phone"),
                type_callable=lambda value:
                    Phone.validate(value),
                is_model_dict=True)

    def __repr__(self):
        """Return a unambiguous string representation."""
        _method=self.method
        _card=self.card
        _billing_address=self.billing_address
        _phone=self.phone
        _additional_properties=self.additional_properties
        return (
            f"{self.__class__.__name__}("
            f"method={_method!r}, "
            f"card={_card!r}, "
            f"billing_address={_billing_address!r}, "
            f"phone={_phone!r}, "
            f"additional_properties={_additional_properties!r}, "
            f")"
        )

    def __str__(self):
        """Return a human-readable string representation."""
        _method=self.method
        _card=self.card
        _billing_address=self.billing_address
        _phone=self.phone
        _additional_properties=self.additional_properties
        return (
            f"{self.__class__.__name__}("
            f"method={_method!s}, "
            f"card={_card!s}, "
            f"billing_address={_billing_address!s}, "
            f"phone={_phone!s}, "
            f"additional_properties={_additional_properties!s}, "
            f")"
        )
