from ....tl.mtproto_request import MTProtoRequest


class PhotosSlice(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. TL definition below.
    photos.photosSlice#15051f54 count:int photos:Vector<Photo> users:Vector<User> = photos.Photos"""

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

    def __init__(self, count, photos, users):
        """
        :param count: Telegram type: "int".
        :param photos: Telegram type: "Photo". Must be a list.
        :param users: Telegram type: "User". Must be a list.

        Constructor for photos.Photos: Instance of either Photos, PhotosSlice.
        """
        super().__init__()

        self.count = count
        self.photos = photos
        self.users = users

    def to_dict(self):
        return {
            'count': self.count,
            'photos': [] if self.photos is None else [None if x is None else x.to_dict() for x in self.photos],
            'users': [] if self.users is None else [None if x is None else x.to_dict() for x in self.users],
        }

    def on_send(self, writer):
        writer.write_int(PhotosSlice.constructor_id, signed=False)
        writer.write_int(self.count)
        writer.write_int(0x1cb5c415, signed=False)  # Vector's constructor ID
        writer.write_int(len(self.photos))
        for photos_item in self.photos:
            photos_item.on_send(writer)

        writer.write_int(0x1cb5c415, signed=False)  # Vector's constructor ID
        writer.write_int(len(self.users))
        for users_item in self.users:
            users_item.on_send(writer)

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

    def on_response(self, reader):
        self.count = reader.read_int()
        reader.read_int()  # Vector's constructor ID
        self.photos = []  # Initialize an empty list
        photos_len = reader.read_int()
        for _ in range(photos_len):
            photos_item = reader.tgread_object()
            self.photos.append(photos_item)

        reader.read_int()  # Vector's constructor ID
        self.users = []  # Initialize an empty list
        users_len = reader.read_int()
        for _ in range(users_len):
            users_item = reader.tgread_object()
            self.users.append(users_item)

    def __repr__(self):
        return 'photos.photosSlice#15051f54 count:int photos:Vector<Photo> users:Vector<User> = photos.Photos'

    def __str__(self):
        return '(photos.photosSlice (ID: 0x15051f54) = (count={}, photos={}, users={}))'.format(str(self.count), None if not self.photos else [str(_) for _ in self.photos], None if not self.users else [str(_) for _ in self.users])
