"""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.buyer_history import (
    BuyerHistory,
)
from cellpointapi.models.loyalty_account import (
    LoyaltyAccount,
)


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

    Account information for the buyer.

    Attributes:
        username (str): Username of the buyer.
        email_address (str): User email address
        account_type (AccountType): The model property of type AccountType.
        account_status (AccountStatus): The model property of type AccountStatus.
        account_level (str): Merchant defined level of the account.
        date_of_birth (date): The shopper's date of birth.  Format ISO-8601:
            YYYY-MM-DD
        gender (Gender): Genders for individuals
        history (BuyerHistory): Buyer's account history, used for fraud checks.
        is_mobile_app_installed (bool): If buyer has installed the merchant's mobile
            app.
        loyalty_account (LoyaltyAccount): Loyalty account information.
        additional_properties (Dict[str, Any]): The additional properties for the
            model.

    """

    # Create a mapping from Model property names to API property names
    _names = {
        "username": "username",
        "email_address": "emailAddress",
        "account_type": "accountType",
        "account_status": "accountStatus",
        "account_level": "accountLevel",
        "date_of_birth": "dateOfBirth",
        "gender": "gender",
        "history": "history",
        "is_mobile_app_installed": "isMobileAppInstalled",
        "loyalty_account": "loyaltyAccount",
    }

    _optionals = [
        "account_type",
        "account_status",
        "account_level",
        "date_of_birth",
        "gender",
        "history",
        "is_mobile_app_installed",
        "loyalty_account",
    ]

    def __init__(
        self,
        username=None,
        email_address=None,
        account_type=APIHelper.SKIP,
        account_status="ACTIVE",
        account_level=APIHelper.SKIP,
        date_of_birth=APIHelper.SKIP,
        gender=APIHelper.SKIP,
        history=APIHelper.SKIP,
        is_mobile_app_installed=APIHelper.SKIP,
        loyalty_account=APIHelper.SKIP,
        additional_properties=None):
        """Initialize a Account instance."""
        # Initialize members of the class
        self.username = username
        self.email_address = email_address
        if account_type is not APIHelper.SKIP:
            self.account_type = account_type
        self.account_status = account_status
        if account_level is not APIHelper.SKIP:
            self.account_level = account_level
        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 history is not APIHelper.SKIP:
            self.history = history
        if is_mobile_app_installed is not APIHelper.SKIP:
            self.is_mobile_app_installed = is_mobile_app_installed
        if loyalty_account is not APIHelper.SKIP:
            self.loyalty_account = loyalty_account

        # 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
        username =\
            dictionary.get("username")\
            if dictionary.get("username")\
                else None
        email_address =\
            dictionary.get("emailAddress")\
            if dictionary.get("emailAddress")\
                else None
        account_type =\
            dictionary.get("accountType")\
            if dictionary.get("accountType")\
                else APIHelper.SKIP
        account_status =\
            dictionary.get("accountStatus")\
            if dictionary.get("accountStatus")\
                else "ACTIVE"
        account_level =\
            dictionary.get("accountLevel")\
            if dictionary.get("accountLevel")\
                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
        history =\
            BuyerHistory.from_dictionary(
                dictionary.get("history"))\
                if "history" in dictionary.keys()\
                else APIHelper.SKIP
        is_mobile_app_installed =\
            dictionary.get("isMobileAppInstalled")\
            if "isMobileAppInstalled" in dictionary.keys()\
                else APIHelper.SKIP
        loyalty_account =\
            LoyaltyAccount.from_dictionary(
                dictionary.get("loyaltyAccount"))\
                if "loyaltyAccount" 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(username,
                   email_address,
                   account_type,
                   account_status,
                   account_level,
                   date_of_birth,
                   gender,
                   history,
                   is_mobile_app_installed,
                   loyalty_account,
                   additional_properties)

    def __repr__(self):
        """Return a unambiguous string representation."""
        _username=self.username
        _email_address=self.email_address
        _account_type=(
            self.account_type
            if hasattr(self, "account_type")
            else None
        )
        _account_status=(
            self.account_status
            if hasattr(self, "account_status")
            else None
        )
        _account_level=(
            self.account_level
            if hasattr(self, "account_level")
            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
        )
        _history=(
            self.history
            if hasattr(self, "history")
            else None
        )
        _is_mobile_app_installed=(
            self.is_mobile_app_installed
            if hasattr(self, "is_mobile_app_installed")
            else None
        )
        _loyalty_account=(
            self.loyalty_account
            if hasattr(self, "loyalty_account")
            else None
        )
        _additional_properties=self.additional_properties
        return (
            f"{self.__class__.__name__}("
            f"username={_username!r}, "
            f"email_address={_email_address!r}, "
            f"account_type={_account_type!r}, "
            f"account_status={_account_status!r}, "
            f"account_level={_account_level!r}, "
            f"date_of_birth={_date_of_birth!r}, "
            f"gender={_gender!r}, "
            f"history={_history!r}, "
            f"is_mobile_app_installed={_is_mobile_app_installed!r}, "
            f"loyalty_account={_loyalty_account!r}, "
            f"additional_properties={_additional_properties!r}, "
            f")"
        )

    def __str__(self):
        """Return a human-readable string representation."""
        _username=self.username
        _email_address=self.email_address
        _account_type=(
            self.account_type
            if hasattr(self, "account_type")
            else None
        )
        _account_status=(
            self.account_status
            if hasattr(self, "account_status")
            else None
        )
        _account_level=(
            self.account_level
            if hasattr(self, "account_level")
            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
        )
        _history=(
            self.history
            if hasattr(self, "history")
            else None
        )
        _is_mobile_app_installed=(
            self.is_mobile_app_installed
            if hasattr(self, "is_mobile_app_installed")
            else None
        )
        _loyalty_account=(
            self.loyalty_account
            if hasattr(self, "loyalty_account")
            else None
        )
        _additional_properties=self.additional_properties
        return (
            f"{self.__class__.__name__}("
            f"username={_username!s}, "
            f"email_address={_email_address!s}, "
            f"account_type={_account_type!s}, "
            f"account_status={_account_status!s}, "
            f"account_level={_account_level!s}, "
            f"date_of_birth={_date_of_birth!s}, "
            f"gender={_gender!s}, "
            f"history={_history!s}, "
            f"is_mobile_app_installed={_is_mobile_app_installed!s}, "
            f"loyalty_account={_loyalty_account!s}, "
            f"additional_properties={_additional_properties!s}, "
            f")"
        )
