from ...tl.mtproto_request import MTProtoRequest


class PhotoCachedSize(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. TL definition below.
    photoCachedSize#e9a734fa type:string location:FileLocation w:int h:int bytes:bytes = PhotoSize"""

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

    def __init__(self, type, location, w, h, bytes):
        """
        :param type: Telegram type: "string".
        :param location: Telegram type: "FileLocation".
        :param w: Telegram type: "int".
        :param h: Telegram type: "int".
        :param bytes: Telegram type: "bytes".

        Constructor for PhotoSize: Instance of either PhotoSizeEmpty, PhotoSize, PhotoCachedSize.
        """
        super().__init__()

        self.type = type
        self.location = location
        self.w = w
        self.h = h
        self.bytes = bytes

    def to_dict(self):
        return {
            'type': self.type,
            'location': None if self.location is None else self.location.to_dict(),
            'w': self.w,
            'h': self.h,
            'bytes': self.bytes,
        }

    def on_send(self, writer):
        writer.write_int(PhotoCachedSize.constructor_id, signed=False)
        writer.tgwrite_string(self.type)
        self.location.on_send(writer)
        writer.write_int(self.w)
        writer.write_int(self.h)
        writer.tgwrite_bytes(self.bytes)

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

    def on_response(self, reader):
        self.type = reader.tgread_string()
        self.location = reader.tgread_object()
        self.w = reader.read_int()
        self.h = reader.read_int()
        self.bytes = reader.tgread_bytes()

    def __repr__(self):
        return 'photoCachedSize#e9a734fa type:string location:FileLocation w:int h:int bytes:bytes = PhotoSize'

    def __str__(self):
        return '(photoCachedSize (ID: 0xe9a734fa) = (type={}, location={}, w={}, h={}, bytes={}))'.format(str(self.type), str(self.location), str(self.w), str(self.h), str(self.bytes))
