from ...tl.mtproto_request import MTProtoRequest


class InputMediaUploadedPhoto(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. Original .tl definition below.
    inputMediaUploadedPhoto#630c9af1 flags:# file:InputFile caption:string stickers:flags.0?Vector<InputDocument> = InputMedia"""

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

    def __init__(self, file, caption, stickers=None):
        """
        :param file: Telegram type: «InputFile».
        :param caption: Telegram type: «string».
        :param stickers: Telegram type: «InputDocument». Must be a list.

        Constructor for InputMedia: Instance of either InputMediaEmpty, InputMediaUploadedPhoto, InputMediaPhoto, InputMediaGeoPoint, InputMediaContact, InputMediaUploadedDocument, InputMediaUploadedThumbDocument, InputMediaDocument, InputMediaVenue, InputMediaGifExternal, InputMediaPhotoExternal, InputMediaDocumentExternal, InputMediaGame, InputMediaInvoice.
        """
        super().__init__()

        self.file = file
        self.caption = caption
        self.stickers = stickers

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

        self.file.on_send(writer)
        writer.tgwrite_string(self.caption)
        if self.stickers:
            writer.write_int(0x1cb5c415, signed=False)  # Vector's constructor ID
            writer.write_int(len(self.stickers))
            for stickers_item in self.stickers:
                if stickers_item:
                    stickers_item.on_send(writer)

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

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

        self.file = reader.tgread_object()
        self.caption = reader.tgread_string()
        if (flags & (1 << 0)) != 0:
            reader.read_int()  # Vector's constructor ID
            self.stickers = []  # Initialize an empty list
            stickers_len = reader.read_int()
            for _ in range(stickers_len):
                stickers_item = reader.tgread_object()
                self.stickers.append(stickers_item)

    def __repr__(self):
        return 'inputMediaUploadedPhoto#630c9af1 flags:# file:InputFile caption:string stickers:flags.0?Vector<InputDocument> = InputMedia'

    def __str__(self):
        return '(inputMediaUploadedPhoto (ID: 0x630c9af1) = (file={}, caption={}, stickers={}))'.format(str(self.file), str(self.caption), None if not self.stickers else [str(_) for _ in self.stickers])
