from ...tl.mtproto_request import MTProtoRequest


class UserFull(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. Original .tl definition below.
    userFull#0f220f3f flags:# blocked:flags.0?true phone_calls_available:flags.4?true phone_calls_private:flags.5?true user:User about:flags.1?string link:contacts.Link profile_photo:flags.2?Photo notify_settings:PeerNotifySettings bot_info:flags.3?BotInfo common_chats_count:int = UserFull"""

    # Telegram's constructor ID (and unique identifier) for this class
    constructor_id = 0xf220f3f

    def __init__(self, user, link, notify_settings, common_chats_count, blocked=None, phone_calls_available=None, phone_calls_private=None, about=None, profile_photo=None, bot_info=None):
        """
        :param blocked: Telegram type: «true».
        :param phone_calls_available: Telegram type: «true».
        :param phone_calls_private: Telegram type: «true».
        :param user: Telegram type: «User».
        :param about: Telegram type: «string».
        :param link: Telegram type: «contacts.Link».
        :param profile_photo: Telegram type: «Photo».
        :param notify_settings: Telegram type: «PeerNotifySettings».
        :param bot_info: Telegram type: «BotInfo».
        :param common_chats_count: Telegram type: «int».

        Constructor for UserFull: Instance of UserFull.
        """
        super().__init__()

        self.blocked = blocked
        self.phone_calls_available = phone_calls_available
        self.phone_calls_private = phone_calls_private
        self.user = user
        self.about = about
        self.link = link
        self.profile_photo = profile_photo
        self.notify_settings = notify_settings
        self.bot_info = bot_info
        self.common_chats_count = common_chats_count

    def on_send(self, writer):
        writer.write_int(UserFull.constructor_id, signed=False)
        # Calculate the flags. This equals to those flag arguments which are NOT None
        flags = 0
        flags |= (1 << 0) if self.blocked else 0
        flags |= (1 << 4) if self.phone_calls_available else 0
        flags |= (1 << 5) if self.phone_calls_private else 0
        flags |= (1 << 1) if self.about else 0
        flags |= (1 << 2) if self.profile_photo else 0
        flags |= (1 << 3) if self.bot_info else 0
        writer.write_int(flags)

        self.user.on_send(writer)
        if self.about:
            writer.tgwrite_string(self.about)

        self.link.on_send(writer)
        if self.profile_photo:
            self.profile_photo.on_send(writer)

        self.notify_settings.on_send(writer)
        if self.bot_info:
            self.bot_info.on_send(writer)

        writer.write_int(self.common_chats_count)

    @staticmethod
    def empty():
        """Returns an "empty" instance (all attributes are None)"""
        return UserFull(None, None, None, None, None, None, None, None, None, None)

    def on_response(self, reader):
        flags = reader.read_int()

        if (flags & (1 << 0)) != 0:
            self.blocked = True  # Arbitrary not-None value, no need to read since it is a flag

        if (flags & (1 << 4)) != 0:
            self.phone_calls_available = True  # Arbitrary not-None value, no need to read since it is a flag

        if (flags & (1 << 5)) != 0:
            self.phone_calls_private = True  # Arbitrary not-None value, no need to read since it is a flag

        self.user = reader.tgread_object()
        if (flags & (1 << 1)) != 0:
            self.about = reader.tgread_string()

        self.link = reader.tgread_object()
        if (flags & (1 << 2)) != 0:
            self.profile_photo = reader.tgread_object()

        self.notify_settings = reader.tgread_object()
        if (flags & (1 << 3)) != 0:
            self.bot_info = reader.tgread_object()

        self.common_chats_count = reader.read_int()

    def __repr__(self):
        return 'userFull#0f220f3f flags:# blocked:flags.0?true phone_calls_available:flags.4?true phone_calls_private:flags.5?true user:User about:flags.1?string link:contacts.Link profile_photo:flags.2?Photo notify_settings:PeerNotifySettings bot_info:flags.3?BotInfo common_chats_count:int = UserFull'

    def __str__(self):
        return '(userFull (ID: 0xf220f3f) = (blocked={}, phone_calls_available={}, phone_calls_private={}, user={}, about={}, link={}, profile_photo={}, notify_settings={}, bot_info={}, common_chats_count={}))'.format(str(self.blocked), str(self.phone_calls_available), str(self.phone_calls_private), str(self.user), str(self.about), str(self.link), str(self.profile_photo), str(self.notify_settings), str(self.bot_info), str(self.common_chats_count))
