from ...tl.mtproto_request import MTProtoRequest


class InputMediaInvoice(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. Original .tl definition below.
    inputMediaInvoice#92153685 flags:# title:string description:string photo:flags.0?InputWebDocument invoice:Invoice payload:bytes provider:string start_param:string = InputMedia"""

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

    def __init__(self, title, description, invoice, payload, provider, start_param, photo=None):
        """
        :param title: Telegram type: «string».
        :param description: Telegram type: «string».
        :param photo: Telegram type: «InputWebDocument».
        :param invoice: Telegram type: «Invoice».
        :param payload: Telegram type: «bytes».
        :param provider: Telegram type: «string».
        :param start_param: Telegram type: «string».

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

        self.title = title
        self.description = description
        self.photo = photo
        self.invoice = invoice
        self.payload = payload
        self.provider = provider
        self.start_param = start_param

    def on_send(self, writer):
        writer.write_int(InputMediaInvoice.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
        writer.write_int(flags)

        writer.tgwrite_string(self.title)
        writer.tgwrite_string(self.description)
        if self.photo:
            self.photo.on_send(writer)

        self.invoice.on_send(writer)
        writer.tgwrite_bytes(self.payload)
        writer.tgwrite_string(self.provider)
        writer.tgwrite_string(self.start_param)

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

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

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

        self.invoice = reader.tgread_object()
        self.payload = reader.tgread_bytes()
        self.provider = reader.tgread_string()
        self.start_param = reader.tgread_string()

    def __repr__(self):
        return 'inputMediaInvoice#92153685 flags:# title:string description:string photo:flags.0?InputWebDocument invoice:Invoice payload:bytes provider:string start_param:string = InputMedia'

    def __str__(self):
        return '(inputMediaInvoice (ID: 0x92153685) = (title={}, description={}, photo={}, invoice={}, payload={}, provider={}, start_param={}))'.format(str(self.title), str(self.description), str(self.photo), str(self.invoice), str(self.payload), str(self.provider), str(self.start_param))
