from ...tl.tlobject import TLObject


class ChannelBannedRights(TLObject):
    """Class generated by TLObjects' generator. All changes will be ERASED. TL definition below.
    channelBannedRights#58cf4249 flags:# view_messages:flags.0?true send_messages:flags.1?true send_media:flags.2?true send_stickers:flags.3?true send_gifs:flags.4?true send_games:flags.5?true send_inline:flags.6?true embed_links:flags.7?true until_date:int = ChannelBannedRights"""

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

    def __init__(self, until_date, view_messages=None, send_messages=None, send_media=None, send_stickers=None, send_gifs=None, send_games=None, send_inline=None, embed_links=None):
        """
        :param view_messages: Telegram type: "true".
        :param send_messages: Telegram type: "true".
        :param send_media: Telegram type: "true".
        :param send_stickers: Telegram type: "true".
        :param send_gifs: Telegram type: "true".
        :param send_games: Telegram type: "true".
        :param send_inline: Telegram type: "true".
        :param embed_links: Telegram type: "true".
        :param until_date: Telegram type: "date".

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

        self.view_messages = view_messages
        self.send_messages = send_messages
        self.send_media = send_media
        self.send_stickers = send_stickers
        self.send_gifs = send_gifs
        self.send_games = send_games
        self.send_inline = send_inline
        self.embed_links = embed_links
        self.until_date = until_date

    def to_dict(self):
        return {
            'view_messages': self.view_messages,
            'send_messages': self.send_messages,
            'send_media': self.send_media,
            'send_stickers': self.send_stickers,
            'send_gifs': self.send_gifs,
            'send_games': self.send_games,
            'send_inline': self.send_inline,
            'embed_links': self.embed_links,
            'until_date': self.until_date,
        }

    def on_send(self, writer):
        writer.write_int(ChannelBannedRights.constructor_id, signed=False)
        # Calculate the flags. This equals to those flag arguments which are NOT None
        flags = 0
        flags |= (1 << 0) if self.view_messages else 0
        flags |= (1 << 1) if self.send_messages else 0
        flags |= (1 << 2) if self.send_media else 0
        flags |= (1 << 3) if self.send_stickers else 0
        flags |= (1 << 4) if self.send_gifs else 0
        flags |= (1 << 5) if self.send_games else 0
        flags |= (1 << 6) if self.send_inline else 0
        flags |= (1 << 7) if self.embed_links else 0
        writer.write_int(flags)

        writer.tgwrite_date(self.until_date)

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

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

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

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

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

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

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

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

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

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

        self.until_date = reader.tgread_date()

    def __repr__(self):
        return 'channelBannedRights#58cf4249 flags:# view_messages:flags.0?true send_messages:flags.1?true send_media:flags.2?true send_stickers:flags.3?true send_gifs:flags.4?true send_games:flags.5?true send_inline:flags.6?true embed_links:flags.7?true until_date:int = ChannelBannedRights'

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

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