from ...tl.tlobject import TLObject


class ChannelAdminRights(TLObject):
    """Class generated by TLObjects' generator. All changes will be ERASED. TL definition below.
    channelAdminRights#5d7ceba5 flags:# change_info:flags.0?true post_messages:flags.1?true edit_messages:flags.2?true delete_messages:flags.3?true ban_users:flags.4?true invite_users:flags.5?true invite_link:flags.6?true pin_messages:flags.7?true add_admins:flags.9?true = ChannelAdminRights"""

    # Telegram's constructor (U)ID for this class
    constructor_id = 0x5d7ceba5
    # Also the ID of its resulting type for fast checks
    subclass_of_id = 0x2286545a

    def __init__(self, change_info=None, post_messages=None, edit_messages=None, delete_messages=None, ban_users=None, invite_users=None, invite_link=None, pin_messages=None, add_admins=None):
        """
        :param change_info: Telegram type: "true".
        :param post_messages: Telegram type: "true".
        :param edit_messages: Telegram type: "true".
        :param delete_messages: Telegram type: "true".
        :param ban_users: Telegram type: "true".
        :param invite_users: Telegram type: "true".
        :param invite_link: Telegram type: "true".
        :param pin_messages: Telegram type: "true".
        :param add_admins: Telegram type: "true".

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

        self.change_info = change_info
        self.post_messages = post_messages
        self.edit_messages = edit_messages
        self.delete_messages = delete_messages
        self.ban_users = ban_users
        self.invite_users = invite_users
        self.invite_link = invite_link
        self.pin_messages = pin_messages
        self.add_admins = add_admins

    def to_dict(self):
        return {
            'change_info': self.change_info,
            'post_messages': self.post_messages,
            'edit_messages': self.edit_messages,
            'delete_messages': self.delete_messages,
            'ban_users': self.ban_users,
            'invite_users': self.invite_users,
            'invite_link': self.invite_link,
            'pin_messages': self.pin_messages,
            'add_admins': self.add_admins,
        }

    def on_send(self, writer):
        writer.write_int(ChannelAdminRights.constructor_id, signed=False)
        # Calculate the flags. This equals to those flag arguments which are NOT None
        flags = 0
        flags |= (1 << 0) if self.change_info else 0
        flags |= (1 << 1) if self.post_messages else 0
        flags |= (1 << 2) if self.edit_messages else 0
        flags |= (1 << 3) if self.delete_messages else 0
        flags |= (1 << 4) if self.ban_users else 0
        flags |= (1 << 5) if self.invite_users else 0
        flags |= (1 << 6) if self.invite_link else 0
        flags |= (1 << 7) if self.pin_messages else 0
        flags |= (1 << 9) if self.add_admins else 0
        writer.write_int(flags)


    @staticmethod
    def empty():
        """Returns an "empty" instance (attributes=None)"""
        return ChannelAdminRights(None, None, None, None, None, None, None, None, None)

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

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

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

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

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

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

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

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

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

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

    def __repr__(self):
        return 'channelAdminRights#5d7ceba5 flags:# change_info:flags.0?true post_messages:flags.1?true edit_messages:flags.2?true delete_messages:flags.3?true ban_users:flags.4?true invite_users:flags.5?true invite_link:flags.6?true pin_messages:flags.7?true add_admins:flags.9?true = ChannelAdminRights'

    def __str__(self):
        return TLObject.pretty_format(self)

    def stringify(self):
        return TLObject.pretty_format(self, indent=0)
