from ...tl.mtproto_request import MTProtoRequest


class InputWebDocument(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. Original .tl definition below.
    inputWebDocument#9bed434d url:string size:int mime_type:string attributes:Vector<DocumentAttribute> = InputWebDocument"""

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

    def __init__(self, url, size, mime_type, attributes):
        """
        :param url: Telegram type: «string».
        :param size: Telegram type: «int».
        :param mime_type: Telegram type: «string».
        :param attributes: Telegram type: «DocumentAttribute». Must be a list.

        Constructor for InputWebDocument: Instance of InputWebDocument.
        """
        super().__init__()

        self.url = url
        self.size = size
        self.mime_type = mime_type
        self.attributes = attributes

    def on_send(self, writer):
        writer.write_int(InputWebDocument.constructor_id, signed=False)
        writer.tgwrite_string(self.url)
        writer.write_int(self.size)
        writer.tgwrite_string(self.mime_type)
        writer.write_int(0x1cb5c415, signed=False)  # Vector's constructor ID
        writer.write_int(len(self.attributes))
        for attributes_item in self.attributes:
            attributes_item.on_send(writer)

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

    def on_response(self, reader):
        self.url = reader.tgread_string()
        self.size = reader.read_int()
        self.mime_type = reader.tgread_string()
        reader.read_int()  # Vector's constructor ID
        self.attributes = []  # Initialize an empty list
        attributes_len = reader.read_int()
        for _ in range(attributes_len):
            attributes_item = reader.tgread_object()
            self.attributes.append(attributes_item)

    def __repr__(self):
        return 'inputWebDocument#9bed434d url:string size:int mime_type:string attributes:Vector<DocumentAttribute> = InputWebDocument'

    def __str__(self):
        return '(inputWebDocument (ID: 0x9bed434d) = (url={}, size={}, mime_type={}, attributes={}))'.format(str(self.url), str(self.size), str(self.mime_type), None if not self.attributes else [str(_) for _ in self.attributes])
