from telethon.tl.mtproto_request import MTProtoRequest


class UpdatePinnedMessageRequest(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. Original .tl definition below.
    channels.updatePinnedMessage#a72ded52 flags:None silent:flags.0?true channel:InputChannel id:int = Updates"""

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

    def __init__(self, channel, id, silent=None):
        """
        :param silent: Telegram type: «true».
        :param channel: Telegram type: «InputChannel».
        :param id: Telegram type: «int».
        """
        super().__init__()
        self.result = None
        self.confirmed = True  # Confirmed by default

        self.silent = silent
        self.channel = channel
        self.id = id

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

        self.channel.on_send(writer)
        writer.write_int(self.id)

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

    def on_response(self, reader):
        self.result = reader.tgread_object()

    def __repr__(self):
        return 'channels.updatePinnedMessage#a72ded52 flags:None silent:flags.0?true channel:InputChannel id:int = Updates'

    def __str__(self):
        return '(channels.updatePinnedMessage (ID: 0xa72ded52) = (silent={}, channel={}, id={}))'.format(str(self.silent), str(self.channel), str(self.id))
