from telethon.tl.mtproto_request import MTProtoRequest


class SendMediaRequest(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. Original .tl definition below.
    messages.sendMedia#c8f16791 flags:None silent:flags.5?true background:flags.6?true clear_draft:flags.7?true peer:InputPeer reply_to_msg_id:flags.0?int media:InputMedia random_id:long reply_markup:flags.2?ReplyMarkup = Updates"""

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

    def __init__(self, peer, media, random_id, silent=None, background=None, clear_draft=None, reply_to_msg_id=None, reply_markup=None):
        """
        :param silent: Telegram type: «true».
        :param background: Telegram type: «true».
        :param clear_draft: Telegram type: «true».
        :param peer: Telegram type: «InputPeer».
        :param reply_to_msg_id: Telegram type: «int».
        :param media: Telegram type: «InputMedia».
        :param random_id: Telegram type: «long».
        :param reply_markup: Telegram type: «ReplyMarkup».
        """
        super().__init__()
        self.result = None
        self.confirmed = True  # Confirmed by default

        self.silent = silent
        self.background = background
        self.clear_draft = clear_draft
        self.peer = peer
        self.reply_to_msg_id = reply_to_msg_id
        self.media = media
        self.random_id = random_id
        self.reply_markup = reply_markup

    def on_send(self, writer):
        writer.write_int(SendMediaRequest.constructor_id, signed=False)
        # Calculate the flags. This equals to those flag arguments which are NOT None
        flags = 0
        flags |= (1 << 5) if self.silent else 0
        flags |= (1 << 6) if self.background else 0
        flags |= (1 << 7) if self.clear_draft else 0
        flags |= (1 << 0) if self.reply_to_msg_id else 0
        flags |= (1 << 2) if self.reply_markup else 0
        writer.write_int(flags)

        self.peer.on_send(writer)
        if self.reply_to_msg_id:
            writer.write_int(self.reply_to_msg_id)

        self.media.on_send(writer)
        writer.write_long(self.random_id)
        if self.reply_markup:
            self.reply_markup.on_send(writer)

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

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

    def __repr__(self):
        return 'messages.sendMedia#c8f16791 flags:None silent:flags.5?true background:flags.6?true clear_draft:flags.7?true peer:InputPeer reply_to_msg_id:flags.0?int media:InputMedia random_id:long reply_markup:flags.2?ReplyMarkup = Updates'

    def __str__(self):
        return '(messages.sendMedia (ID: 0xc8f16791) = (silent={}, background={}, clear_draft={}, peer={}, reply_to_msg_id={}, media={}, random_id={}, reply_markup={}))'.format(str(self.silent), str(self.background), str(self.clear_draft), str(self.peer), str(self.reply_to_msg_id), str(self.media), str(self.random_id), str(self.reply_markup))
