import logging
import json
import asyncio
from charlesbot.util.slack import slack_rtm_api_call


class SlackUser(object):

    main_properties = ['id',
                       'name',
                       'deleted',
                       'color',
                       'is_admin',
                       'is_owner',
                       'has_2fa',
                       'is_bot']

    profile_properties = ['first_name',
                          'last_name',
                          'real_name',
                          'email',
                          'image_24']

    def __init__(self, **kwargs):
        self.log = logging.getLogger(__name__)
        merged_properties = self.main_properties + self.profile_properties
        for prop in merged_properties:
            setattr(self, prop, kwargs.get(prop, ""))

    @asyncio.coroutine
    def retrieve_slack_user_info(self, slack_client, user_id):
        result = yield from slack_rtm_api_call(
            slack_client,
            'users.info',
            user=user_id
        )
        self.load(json.loads(result))

    def load(self, user_dict):
        for prop in self.main_properties:
            default = getattr(self, prop)
            setattr(self, prop, user_dict.get('user', {}).get(prop, default))  # NOQA

        for prop in self.profile_properties:
            default = getattr(self, prop)
            setattr(self, prop, user_dict.get('user', {}).get('profile', {}).get(prop, default))  # NOQA

    def __str__(self):
        return_dict = {}
        merged_properties = self.main_properties + self.profile_properties
        for prop in merged_properties:
            return_dict.update({prop: getattr(self, prop)})
        return json.dumps(return_dict)

    def __eq__(self, other):
        merged_properties = self.main_properties + self.profile_properties
        for prop in merged_properties:
            if not getattr(self, prop) == getattr(other, prop):
                self.log.debug("Property %s is different" % prop)
                self.log.debug("%s != %s" % (getattr(self, prop),
                                             getattr(other, prop)))
                return False
        return True

    def __ne__(self, other):
        return not self.__eq__(other)

@@ -1,19 +1,4 @@
-import logging%0A
 impo
@@ -73,16 +73,62 @@
 pi_call%0A
+from charlesbot.base_object import BaseObject%0A
 %0A%0Aclass 
@@ -137,17 +137,21 @@
 ackUser(
-o
+BaseO
 bject):%0A
@@ -615,100 +615,8 @@
     
-def __init__(self, **kwargs):%0A        self.log = logging.getLogger(__name__)%0A        merged_
 prop
@@ -616,37 +616,32 @@
    properties = 
-self.
 main_properties 
@@ -634,37 +634,32 @@
 in_properties + 
-self.
 profile_properti
@@ -665,99 +665,76 @@
 ies%0A
-        for prop in merged_properties:%0A            setattr(self, prop, kwargs.get(prop, %22%22)
+%0A    def __init__(self, **kwargs):%0A        super().__init__(**kwargs
 )%0A%0A 
@@ -1390,791 +1390,4 @@
 OQA%0A
-%0A    def __str__(self):%0A        return_dict = %7B%7D%0A        merged_properties = self.main_properties + self.profile_properties%0A        for prop in merged_properties:%0A            return_dict.update(%7Bprop: getattr(self, prop)%7D)%0A        return json.dumps(return_dict)%0A%0A    def __eq__(self, other):%0A        merged_properties = self.main_properties + self.profile_properties%0A        for prop in merged_properties:%0A            if not getattr(self, prop) == getattr(other, prop):%0A                self.log.debug(%22Property %25s is different%22 %25 prop)%0A                self.log.debug(%22%25s != %25s%22 %25 (getattr(self, prop),%0A                                             getattr(other, prop)))%0A                return False%0A        return True%0A%0A    def __ne__(self, other):%0A        return not self.__eq__(other)%0A

Refactor the SlackUser class to inherit from BaseObject