from ...tl.mtproto_request import MTProtoRequest


class WallPaper(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. TL definition below.
    wallPaper#ccb03657 id:int title:string sizes:Vector<PhotoSize> color:int = WallPaper"""

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

    def __init__(self, id, title, sizes, color):
        """
        :param id: Telegram type: "int".
        :param title: Telegram type: "string".
        :param sizes: Telegram type: "PhotoSize". Must be a list.
        :param color: Telegram type: "int".

        Constructor for WallPaper: Instance of either WallPaper, WallPaperSolid.
        """
        super().__init__()

        self.id = id
        self.title = title
        self.sizes = sizes
        self.color = color

    def to_dict(self):
        return {
            'id': self.id,
            'title': self.title,
            'sizes': [] if self.sizes is None else [None if x is None else x.to_dict() for x in self.sizes],
            'color': self.color,
        }

    def on_send(self, writer):
        writer.write_int(WallPaper.constructor_id, signed=False)
        writer.write_int(self.id)
        writer.tgwrite_string(self.title)
        writer.write_int(0x1cb5c415, signed=False)  # Vector's constructor ID
        writer.write_int(len(self.sizes))
        for sizes_item in self.sizes:
            sizes_item.on_send(writer)

        writer.write_int(self.color)

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

    def on_response(self, reader):
        self.id = reader.read_int()
        self.title = reader.tgread_string()
        reader.read_int()  # Vector's constructor ID
        self.sizes = []  # Initialize an empty list
        sizes_len = reader.read_int()
        for _ in range(sizes_len):
            sizes_item = reader.tgread_object()
            self.sizes.append(sizes_item)

        self.color = reader.read_int()

    def __repr__(self):
        return 'wallPaper#ccb03657 id:int title:string sizes:Vector<PhotoSize> color:int = WallPaper'

    def __str__(self):
        return '(wallPaper (ID: 0xccb03657) = (id={}, title={}, sizes={}, color={}))'.format(str(self.id), str(self.title), None if not self.sizes else [str(_) for _ in self.sizes], str(self.color))
