"""mindbodypublicapi.

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

# ruff: noqa: E501
from mindbodypublicapi.api_helper import APIHelper
from mindbodypublicapi.models.user import User


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

    POST UserToken/Issue successful response

    Attributes:
        token_type (str): The model property of type str.
        access_token (str): The authentication token value.
        expires (datetime): Token expiration in UTC.
        user (User): The model property of type User.

    """

    # Create a mapping from Model property names to API property names
    _names = {
        "token_type": "TokenType",
        "access_token": "AccessToken",
        "expires": "Expires",
        "user": "User",
    }

    _optionals = [
        "token_type",
        "access_token",
        "expires",
        "user",
    ]

    def __init__(
        self,
        token_type=APIHelper.SKIP,
        access_token=APIHelper.SKIP,
        expires=APIHelper.SKIP,
        user=APIHelper.SKIP):
        """Initialize a IssueResponse instance."""
        # Initialize members of the class
        if token_type is not APIHelper.SKIP:
            self.token_type = token_type
        if access_token is not APIHelper.SKIP:
            self.access_token = access_token
        if expires is not APIHelper.SKIP:
            self.expires =\
                 APIHelper.apply_datetime_converter(
                expires, APIHelper.RFC3339DateTime)\
                 if expires else None
        if user is not APIHelper.SKIP:
            self.user = user

    @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
        token_type =\
            dictionary.get("TokenType")\
            if dictionary.get("TokenType")\
                else APIHelper.SKIP
        access_token =\
            dictionary.get("AccessToken")\
            if dictionary.get("AccessToken")\
                else APIHelper.SKIP
        expires = APIHelper.RFC3339DateTime.from_value(
            dictionary.get("Expires")).datetime\
            if dictionary.get("Expires") else APIHelper.SKIP
        user =\
            User.from_dictionary(
                dictionary.get("User"))\
                if "User" in dictionary.keys()\
                else APIHelper.SKIP

        # Return an object of this model
        return cls(token_type,
                   access_token,
                   expires,
                   user)

    def __repr__(self):
        """Return a unambiguous string representation."""
        _token_type=(
            self.token_type
            if hasattr(self, "token_type")
            else None
        )
        _access_token=(
            self.access_token
            if hasattr(self, "access_token")
            else None
        )
        _expires=(
            self.expires
            if hasattr(self, "expires")
            else None
        )
        _user=(
            self.user
            if hasattr(self, "user")
            else None
        )
        return (
            f"{self.__class__.__name__}("
            f"token_type={_token_type!r}, "
            f"access_token={_access_token!r}, "
            f"expires={_expires!r}, "
            f"user={_user!r}, "
            f")"
        )

    def __str__(self):
        """Return a human-readable string representation."""
        _token_type=(
            self.token_type
            if hasattr(self, "token_type")
            else None
        )
        _access_token=(
            self.access_token
            if hasattr(self, "access_token")
            else None
        )
        _expires=(
            self.expires
            if hasattr(self, "expires")
            else None
        )
        _user=(
            self.user
            if hasattr(self, "user")
            else None
        )
        return (
            f"{self.__class__.__name__}("
            f"token_type={_token_type!s}, "
            f"access_token={_access_token!s}, "
            f"expires={_expires!s}, "
            f"user={_user!s}, "
            f")"
        )
