from ...tl.mtproto_request import MTProtoRequest


class ChannelForbidden(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. Original .tl definition below.
    channelForbidden#8537784f flags:# broadcast:flags.5?true megagroup:flags.8?true id:int access_hash:long title:string = Chat"""

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

    def __init__(self, id, access_hash, title, broadcast=None, megagroup=None):
        """
        :param broadcast: Telegram type: «true».
        :param megagroup: Telegram type: «true».
        :param id: Telegram type: «int».
        :param access_hash: Telegram type: «long».
        :param title: Telegram type: «string».

        Constructor for Chat: Instance of either ChatEmpty, Chat, ChatForbidden, Channel, ChannelForbidden.
        """
        super().__init__()

        self.broadcast = broadcast
        self.megagroup = megagroup
        self.id = id
        self.access_hash = access_hash
        self.title = title

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

        writer.write_int(self.id)
        writer.write_long(self.access_hash)
        writer.tgwrite_string(self.title)

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

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

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

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

        self.id = reader.read_int()
        self.access_hash = reader.read_long()
        self.title = reader.tgread_string()

    def __repr__(self):
        return 'channelForbidden#8537784f flags:# broadcast:flags.5?true megagroup:flags.8?true id:int access_hash:long title:string = Chat'

    def __str__(self):
        return '(channelForbidden (ID: 0x8537784f) = (broadcast={}, megagroup={}, id={}, access_hash={}, title={}))'.format(str(self.broadcast), str(self.megagroup), str(self.id), str(self.access_hash), str(self.title))
