from ...tl.mtproto_request import MTProtoRequest


class User(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. Original .tl definition below.
    user#2e13f4c3 flags:# is_self:flags.10?true contact:flags.11?true mutual_contact:flags.12?true deleted:flags.13?true bot:flags.14?true bot_chat_history:flags.15?true bot_nochats:flags.16?true verified:flags.17?true restricted:flags.18?true min:flags.20?true bot_inline_geo:flags.21?true id:int access_hash:flags.0?long first_name:flags.1?string last_name:flags.2?string username:flags.3?string phone:flags.4?string photo:flags.5?UserProfilePhoto status:flags.6?UserStatus bot_info_version:flags.14?int restriction_reason:flags.18?string bot_inline_placeholder:flags.19?string lang_code:flags.22?string = User"""

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

    def __init__(self, id, is_self=None, contact=None, mutual_contact=None, deleted=None, bot=None, bot_chat_history=None, bot_nochats=None, verified=None, restricted=None, min=None, bot_inline_geo=None, access_hash=None, first_name=None, last_name=None, username=None, phone=None, photo=None, status=None, bot_info_version=None, restriction_reason=None, bot_inline_placeholder=None, lang_code=None):
        """
        :param is_self: Telegram type: «true».
        :param contact: Telegram type: «true».
        :param mutual_contact: Telegram type: «true».
        :param deleted: Telegram type: «true».
        :param bot: Telegram type: «true».
        :param bot_chat_history: Telegram type: «true».
        :param bot_nochats: Telegram type: «true».
        :param verified: Telegram type: «true».
        :param restricted: Telegram type: «true».
        :param min: Telegram type: «true».
        :param bot_inline_geo: Telegram type: «true».
        :param id: Telegram type: «int».
        :param access_hash: Telegram type: «long».
        :param first_name: Telegram type: «string».
        :param last_name: Telegram type: «string».
        :param username: Telegram type: «string».
        :param phone: Telegram type: «string».
        :param photo: Telegram type: «UserProfilePhoto».
        :param status: Telegram type: «UserStatus».
        :param bot_info_version: Telegram type: «int».
        :param restriction_reason: Telegram type: «string».
        :param bot_inline_placeholder: Telegram type: «string».
        :param lang_code: Telegram type: «string».

        Constructor for User: Instance of either UserEmpty, User.
        """
        super().__init__()

        self.is_self = is_self
        self.contact = contact
        self.mutual_contact = mutual_contact
        self.deleted = deleted
        self.bot = bot
        self.bot_chat_history = bot_chat_history
        self.bot_nochats = bot_nochats
        self.verified = verified
        self.restricted = restricted
        self.min = min
        self.bot_inline_geo = bot_inline_geo
        self.id = id
        self.access_hash = access_hash
        self.first_name = first_name
        self.last_name = last_name
        self.username = username
        self.phone = phone
        self.photo = photo
        self.status = status
        self.bot_info_version = bot_info_version
        self.restriction_reason = restriction_reason
        self.bot_inline_placeholder = bot_inline_placeholder
        self.lang_code = lang_code

    def on_send(self, writer):
        writer.write_int(User.constructor_id, signed=False)
        # Calculate the flags. This equals to those flag arguments which are NOT None
        flags = 0
        flags |= (1 << 10) if self.is_self else 0
        flags |= (1 << 11) if self.contact else 0
        flags |= (1 << 12) if self.mutual_contact else 0
        flags |= (1 << 13) if self.deleted else 0
        flags |= (1 << 14) if self.bot else 0
        flags |= (1 << 15) if self.bot_chat_history else 0
        flags |= (1 << 16) if self.bot_nochats else 0
        flags |= (1 << 17) if self.verified else 0
        flags |= (1 << 18) if self.restricted else 0
        flags |= (1 << 20) if self.min else 0
        flags |= (1 << 21) if self.bot_inline_geo else 0
        flags |= (1 << 0) if self.access_hash else 0
        flags |= (1 << 1) if self.first_name else 0
        flags |= (1 << 2) if self.last_name else 0
        flags |= (1 << 3) if self.username else 0
        flags |= (1 << 4) if self.phone else 0
        flags |= (1 << 5) if self.photo else 0
        flags |= (1 << 6) if self.status else 0
        flags |= (1 << 14) if self.bot_info_version else 0
        flags |= (1 << 18) if self.restriction_reason else 0
        flags |= (1 << 19) if self.bot_inline_placeholder else 0
        flags |= (1 << 22) if self.lang_code else 0
        writer.write_int(flags)

        writer.write_int(self.id)
        if self.access_hash:
            writer.write_long(self.access_hash)

        if self.first_name:
            writer.tgwrite_string(self.first_name)

        if self.last_name:
            writer.tgwrite_string(self.last_name)

        if self.username:
            writer.tgwrite_string(self.username)

        if self.phone:
            writer.tgwrite_string(self.phone)

        if self.photo:
            self.photo.on_send(writer)

        if self.status:
            self.status.on_send(writer)

        if self.bot_info_version:
            writer.write_int(self.bot_info_version)

        if self.restriction_reason:
            writer.tgwrite_string(self.restriction_reason)

        if self.bot_inline_placeholder:
            writer.tgwrite_string(self.bot_inline_placeholder)

        if self.lang_code:
            writer.tgwrite_string(self.lang_code)

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

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

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

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

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

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

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

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

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

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

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

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

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

        self.id = reader.read_int()
        if (flags & (1 << 0)) != 0:
            self.access_hash = reader.read_long()

        if (flags & (1 << 1)) != 0:
            self.first_name = reader.tgread_string()

        if (flags & (1 << 2)) != 0:
            self.last_name = reader.tgread_string()

        if (flags & (1 << 3)) != 0:
            self.username = reader.tgread_string()

        if (flags & (1 << 4)) != 0:
            self.phone = reader.tgread_string()

        if (flags & (1 << 5)) != 0:
            self.photo = reader.tgread_object()

        if (flags & (1 << 6)) != 0:
            self.status = reader.tgread_object()

        if (flags & (1 << 14)) != 0:
            self.bot_info_version = reader.read_int()

        if (flags & (1 << 18)) != 0:
            self.restriction_reason = reader.tgread_string()

        if (flags & (1 << 19)) != 0:
            self.bot_inline_placeholder = reader.tgread_string()

        if (flags & (1 << 22)) != 0:
            self.lang_code = reader.tgread_string()

    def __repr__(self):
        return 'user#2e13f4c3 flags:# is_self:flags.10?true contact:flags.11?true mutual_contact:flags.12?true deleted:flags.13?true bot:flags.14?true bot_chat_history:flags.15?true bot_nochats:flags.16?true verified:flags.17?true restricted:flags.18?true min:flags.20?true bot_inline_geo:flags.21?true id:int access_hash:flags.0?long first_name:flags.1?string last_name:flags.2?string username:flags.3?string phone:flags.4?string photo:flags.5?UserProfilePhoto status:flags.6?UserStatus bot_info_version:flags.14?int restriction_reason:flags.18?string bot_inline_placeholder:flags.19?string lang_code:flags.22?string = User'

    def __str__(self):
        return '(user (ID: 0x2e13f4c3) = (is_self={}, contact={}, mutual_contact={}, deleted={}, bot={}, bot_chat_history={}, bot_nochats={}, verified={}, restricted={}, min={}, bot_inline_geo={}, id={}, access_hash={}, first_name={}, last_name={}, username={}, phone={}, photo={}, status={}, bot_info_version={}, restriction_reason={}, bot_inline_placeholder={}, lang_code={}))'.format(str(self.is_self), str(self.contact), str(self.mutual_contact), str(self.deleted), str(self.bot), str(self.bot_chat_history), str(self.bot_nochats), str(self.verified), str(self.restricted), str(self.min), str(self.bot_inline_geo), str(self.id), str(self.access_hash), str(self.first_name), str(self.last_name), str(self.username), str(self.phone), str(self.photo), str(self.status), str(self.bot_info_version), str(self.restriction_reason), str(self.bot_inline_placeholder), str(self.lang_code))
