"""cellpointapi.

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

# ruff: noqa: E501
import dateutil.parser

from cellpointapi.api_helper import APIHelper
from cellpointapi.models.phone import Phone


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

    Person information.

    Attributes:
        given_name (str): Name bestowed upon an individual to differentiate them from
            other members of a group that share a family name.  In the U.S., the
            first name of a Person.
        family_name (str): Name bestowed upon an individual to denote membership in a
            group or family.  In the U.S., the last name of a Person.
        middle_name (str): Secondary name bestowed upon an individual to
            differentiate them from others that have the same given name.
        name_prefix (str): The portion of a name's full form of address that precedes
            the name itself.
        name_suffix (str): The portion of a name's full form of address that follows
            the name itself.
        date_of_birth (date): The shopper's date of birth.  Format ISO-8601:
            YYYY-MM-DD
        gender (Gender): Genders for individuals
        email (str): User email 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 = {
        "given_name": "givenName",
        "family_name": "familyName",
        "middle_name": "middleName",
        "name_prefix": "namePrefix",
        "name_suffix": "nameSuffix",
        "date_of_birth": "dateOfBirth",
        "gender": "gender",
        "email": "email",
        "phone": "phone",
    }

    _optionals = [
        "middle_name",
        "name_prefix",
        "name_suffix",
        "date_of_birth",
        "gender",
        "email",
        "phone",
    ]

    def __init__(
        self,
        given_name=None,
        family_name=None,
        middle_name=APIHelper.SKIP,
        name_prefix=APIHelper.SKIP,
        name_suffix=APIHelper.SKIP,
        date_of_birth=APIHelper.SKIP,
        gender=APIHelper.SKIP,
        email=APIHelper.SKIP,
        phone=APIHelper.SKIP,
        additional_properties=None):
        """Initialize a Person instance."""
        # Initialize members of the class
        self.given_name = given_name
        self.family_name = family_name
        if middle_name is not APIHelper.SKIP:
            self.middle_name = middle_name
        if name_prefix is not APIHelper.SKIP:
            self.name_prefix = name_prefix
        if name_suffix is not APIHelper.SKIP:
            self.name_suffix = name_suffix
        if date_of_birth is not APIHelper.SKIP:
            self.date_of_birth = date_of_birth
        if gender is not APIHelper.SKIP:
            self.gender = gender
        if email is not APIHelper.SKIP:
            self.email = email
        if phone is not APIHelper.SKIP:
            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
        given_name =\
            dictionary.get("givenName")\
            if dictionary.get("givenName")\
                else None
        family_name =\
            dictionary.get("familyName")\
            if dictionary.get("familyName")\
                else None
        middle_name =\
            dictionary.get("middleName")\
            if dictionary.get("middleName")\
                else APIHelper.SKIP
        name_prefix =\
            dictionary.get("namePrefix")\
            if dictionary.get("namePrefix")\
                else APIHelper.SKIP
        name_suffix =\
            dictionary.get("nameSuffix")\
            if dictionary.get("nameSuffix")\
                else APIHelper.SKIP
        date_of_birth = dateutil.parser.parse(
            dictionary.get("dateOfBirth")).date()\
            if dictionary.get("dateOfBirth") else APIHelper.SKIP
        gender =\
            dictionary.get("gender")\
            if dictionary.get("gender")\
                else APIHelper.SKIP
        email =\
            dictionary.get("email")\
            if dictionary.get("email")\
                else APIHelper.SKIP
        phone =\
            Phone.from_dictionary(
                dictionary.get("phone"))\
                if "phone" in dictionary.keys()\
                else APIHelper.SKIP

        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(given_name,
                   family_name,
                   middle_name,
                   name_prefix,
                   name_suffix,
                   date_of_birth,
                   gender,
                   email,
                   phone,
                   additional_properties)

    def __repr__(self):
        """Return a unambiguous string representation."""
        _given_name=self.given_name
        _family_name=self.family_name
        _middle_name=(
            self.middle_name
            if hasattr(self, "middle_name")
            else None
        )
        _name_prefix=(
            self.name_prefix
            if hasattr(self, "name_prefix")
            else None
        )
        _name_suffix=(
            self.name_suffix
            if hasattr(self, "name_suffix")
            else None
        )
        _date_of_birth=(
            self.date_of_birth
            if hasattr(self, "date_of_birth")
            else None
        )
        _gender=(
            self.gender
            if hasattr(self, "gender")
            else None
        )
        _email=(
            self.email
            if hasattr(self, "email")
            else None
        )
        _phone=(
            self.phone
            if hasattr(self, "phone")
            else None
        )
        _additional_properties=self.additional_properties
        return (
            f"{self.__class__.__name__}("
            f"given_name={_given_name!r}, "
            f"family_name={_family_name!r}, "
            f"middle_name={_middle_name!r}, "
            f"name_prefix={_name_prefix!r}, "
            f"name_suffix={_name_suffix!r}, "
            f"date_of_birth={_date_of_birth!r}, "
            f"gender={_gender!r}, "
            f"email={_email!r}, "
            f"phone={_phone!r}, "
            f"additional_properties={_additional_properties!r}, "
            f")"
        )

    def __str__(self):
        """Return a human-readable string representation."""
        _given_name=self.given_name
        _family_name=self.family_name
        _middle_name=(
            self.middle_name
            if hasattr(self, "middle_name")
            else None
        )
        _name_prefix=(
            self.name_prefix
            if hasattr(self, "name_prefix")
            else None
        )
        _name_suffix=(
            self.name_suffix
            if hasattr(self, "name_suffix")
            else None
        )
        _date_of_birth=(
            self.date_of_birth
            if hasattr(self, "date_of_birth")
            else None
        )
        _gender=(
            self.gender
            if hasattr(self, "gender")
            else None
        )
        _email=(
            self.email
            if hasattr(self, "email")
            else None
        )
        _phone=(
            self.phone
            if hasattr(self, "phone")
            else None
        )
        _additional_properties=self.additional_properties
        return (
            f"{self.__class__.__name__}("
            f"given_name={_given_name!s}, "
            f"family_name={_family_name!s}, "
            f"middle_name={_middle_name!s}, "
            f"name_prefix={_name_prefix!s}, "
            f"name_suffix={_name_suffix!s}, "
            f"date_of_birth={_date_of_birth!s}, "
            f"gender={_gender!s}, "
            f"email={_email!s}, "
            f"phone={_phone!s}, "
            f"additional_properties={_additional_properties!s}, "
            f")"
        )
