from ...tl.tlobject import TLObject


class ChannelParticipantBanned(TLObject):
    """Class generated by TLObjects' generator. All changes will be ERASED. TL definition below.
    channelParticipantBanned#222c1886 flags:# left:flags.0?true user_id:int kicked_by:int date:int banned_rights:ChannelBannedRights = ChannelParticipant"""

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

    def __init__(self, user_id, kicked_by, date, banned_rights, left=None):
        """
        :param left: Telegram type: "true".
        :param user_id: Telegram type: "int".
        :param kicked_by: Telegram type: "int".
        :param date: Telegram type: "date".
        :param banned_rights: Telegram type: "ChannelBannedRights".

        Constructor for ChannelParticipant: Instance of either ChannelParticipant, ChannelParticipantSelf, ChannelParticipantCreator, ChannelParticipantAdmin, ChannelParticipantBanned.
        """
        super().__init__()

        self.left = left
        self.user_id = user_id
        self.kicked_by = kicked_by
        self.date = date
        self.banned_rights = banned_rights

    def to_dict(self):
        return {
            'left': self.left,
            'user_id': self.user_id,
            'kicked_by': self.kicked_by,
            'date': self.date,
            'banned_rights': None if self.banned_rights is None else self.banned_rights.to_dict(),
        }

    def on_send(self, writer):
        writer.write_int(ChannelParticipantBanned.constructor_id, signed=False)
        # Calculate the flags. This equals to those flag arguments which are NOT None
        flags = 0
        flags |= (1 << 0) if self.left else 0
        writer.write_int(flags)

        writer.write_int(self.user_id)
        writer.write_int(self.kicked_by)
        writer.tgwrite_date(self.date)
        self.banned_rights.on_send(writer)

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

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

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

        self.user_id = reader.read_int()
        self.kicked_by = reader.read_int()
        self.date = reader.tgread_date()
        self.banned_rights = reader.tgread_object()

    def __repr__(self):
        return 'channelParticipantBanned#222c1886 flags:# left:flags.0?true user_id:int kicked_by:int date:int banned_rights:ChannelBannedRights = ChannelParticipant'

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

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