from ...tl.tlobject import TLObject


class BotInlineMediaResult(TLObject):
    """Class generated by TLObjects' generator. All changes will be ERASED. TL definition below.
    botInlineMediaResult#17db940b flags:# id:string type:string photo:flags.0?Photo document:flags.1?Document title:flags.2?string description:flags.3?string send_message:BotInlineMessage = BotInlineResult"""

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

    def __init__(self, id, type, send_message, photo=None, document=None, title=None, description=None):
        """
        :param id: Telegram type: "string".
        :param type: Telegram type: "string".
        :param photo: Telegram type: "Photo".
        :param document: Telegram type: "Document".
        :param title: Telegram type: "string".
        :param description: Telegram type: "string".
        :param send_message: Telegram type: "BotInlineMessage".

        Constructor for BotInlineResult: Instance of either BotInlineResult, BotInlineMediaResult.
        """
        super().__init__()

        self.id = id
        self.type = type
        self.photo = photo
        self.document = document
        self.title = title
        self.description = description
        self.send_message = send_message

    def to_dict(self):
        return {
            'id': self.id,
            'type': self.type,
            'photo': None if self.photo is None else self.photo.to_dict(),
            'document': None if self.document is None else self.document.to_dict(),
            'title': self.title,
            'description': self.description,
            'send_message': None if self.send_message is None else self.send_message.to_dict(),
        }

    def on_send(self, writer):
        writer.write_int(BotInlineMediaResult.constructor_id, signed=False)
        # Calculate the flags. This equals to those flag arguments which are NOT None
        flags = 0
        flags |= (1 << 0) if self.photo else 0
        flags |= (1 << 1) if self.document else 0
        flags |= (1 << 2) if self.title else 0
        flags |= (1 << 3) if self.description else 0
        writer.write_int(flags)

        writer.tgwrite_string(self.id)
        writer.tgwrite_string(self.type)
        if self.photo:
            self.photo.on_send(writer)

        if self.document:
            self.document.on_send(writer)

        if self.title:
            writer.tgwrite_string(self.title)

        if self.description:
            writer.tgwrite_string(self.description)

        self.send_message.on_send(writer)

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

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

        self.id = reader.tgread_string()
        self.type = reader.tgread_string()
        if (flags & (1 << 0)) != 0:
            self.photo = reader.tgread_object()

        if (flags & (1 << 1)) != 0:
            self.document = reader.tgread_object()

        if (flags & (1 << 2)) != 0:
            self.title = reader.tgread_string()

        if (flags & (1 << 3)) != 0:
            self.description = reader.tgread_string()

        self.send_message = reader.tgread_object()

    def __repr__(self):
        return 'botInlineMediaResult#17db940b flags:# id:string type:string photo:flags.0?Photo document:flags.1?Document title:flags.2?string description:flags.3?string send_message:BotInlineMessage = BotInlineResult'

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

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