from ...tl.tlobject import TLObject


class Photo(TLObject):
    """Class generated by TLObjects' generator. All changes will be ERASED. TL definition below.
    photo#9288dd29 flags:# has_stickers:flags.0?true id:long access_hash:long date:int sizes:Vector<PhotoSize> = Photo"""

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

    def __init__(self, id, access_hash, date, sizes, has_stickers=None):
        """
        :param has_stickers: Telegram type: "true".
        :param id: Telegram type: "long".
        :param access_hash: Telegram type: "long".
        :param date: Telegram type: "date".
        :param sizes: Telegram type: "PhotoSize". Must be a list.

        Constructor for Photo: Instance of either PhotoEmpty, Photo.
        """
        super().__init__()

        self.has_stickers = has_stickers
        self.id = id
        self.access_hash = access_hash
        self.date = date
        self.sizes = sizes

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

    def on_send(self, writer):
        writer.write_int(Photo.constructor_id, signed=False)
        # Calculate the flags. This equals to those flag arguments which are NOT None
        flags = 0
        flags |= (1 << 0) if self.has_stickers else 0
        writer.write_int(flags)

        writer.write_long(self.id)
        writer.write_long(self.access_hash)
        writer.tgwrite_date(self.date)
        writer.write_int(0x1cb5c415, signed=False)  # Vector's constructor ID
        writer.write_int(len(self.sizes))
        for _x in self.sizes:
            _x.on_send(writer)

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

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

        if (flags & (1 << 0)) != 0:
            self.has_stickers = True  # Arbitrary not-None value, no need to read since it is a flag

        self.id = reader.read_long()
        self.access_hash = reader.read_long()
        self.date = reader.tgread_date()
        reader.read_int()  # Vector's constructor ID
        self.sizes = []  # Initialize an empty list
        _len = reader.read_int()
        for _ in range(_len):
            _x = reader.tgread_object()
            self.sizes.append(_x)

    def __repr__(self):
        return 'photo#9288dd29 flags:# has_stickers:flags.0?true id:long access_hash:long date:int sizes:Vector<PhotoSize> = Photo'

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

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