from ...tl.mtproto_request import MTProtoRequest


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

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

    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 to_dict(self):
        return {
            'url': self.url,
            'size': self.size,
            'mime_type': self.mime_type,
            'attributes': [] if self.attributes is None else [None if x is None else x.to_dict() for x in self.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 (attributes=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])
