"""File auto-generated by tglib TL generator. Do not edit manually."""
from ..tlobject import TLObject
from typing import Optional, List, Union
import os
import struct
from datetime import datetime


class Photo(TLObject):
    """TL type: photos.photo"""
    CONSTRUCTOR_ID = 0x20212ca8
    SUBCLASS_OF_ID = 0xc292bd24

    def __init__(self, photo: 'TypePhoto', users: List['TypeUser']):
        self.photo = photo
        self.users = users

    def to_dict(self):
        return {
            '_': 'Photo',
            'photo': self.photo,
            'users': self.users,
        }

    def _bytes(self) -> bytes:
        import io
        buf = io.BytesIO()
        buf.write(struct.pack('<I', self.CONSTRUCTOR_ID))
        buf.write(bytes(self.photo))
        buf.write(struct.pack('<i', 0x1cb5c415))  # vector id
        buf.write(struct.pack('<i', len(self.users)))
        for item in self.users:
            buf.write(bytes(self.item))
        return buf.getvalue()

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        _val_photo = reader.tgread_object()
        _args['photo'] = _val_photo
        reader.read_int(signed=False)  # skip vector id
        _count_users = reader.read_int()
        _list_users = []
        for _ in range(_count_users):
            _item_users = reader.tgread_object()
            _list_users.append(_item_users)
        _args['users'] = _list_users
        return cls(**_args)


class Photos(TLObject):
    """TL type: photos.photos"""
    CONSTRUCTOR_ID = 0x8dca6aa5
    SUBCLASS_OF_ID = 0x27cfb967

    def __init__(self, photos: List['TypePhoto'], users: List['TypeUser']):
        self.photos = photos
        self.users = users

    def to_dict(self):
        return {
            '_': 'Photos',
            'photos': self.photos,
            'users': self.users,
        }

    def _bytes(self) -> bytes:
        import io
        buf = io.BytesIO()
        buf.write(struct.pack('<I', self.CONSTRUCTOR_ID))
        buf.write(struct.pack('<i', 0x1cb5c415))  # vector id
        buf.write(struct.pack('<i', len(self.photos)))
        for item in self.photos:
            buf.write(bytes(self.item))
        buf.write(struct.pack('<i', 0x1cb5c415))  # vector id
        buf.write(struct.pack('<i', len(self.users)))
        for item in self.users:
            buf.write(bytes(self.item))
        return buf.getvalue()

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        reader.read_int(signed=False)  # skip vector id
        _count_photos = reader.read_int()
        _list_photos = []
        for _ in range(_count_photos):
            _item_photos = reader.tgread_object()
            _list_photos.append(_item_photos)
        _args['photos'] = _list_photos
        reader.read_int(signed=False)  # skip vector id
        _count_users = reader.read_int()
        _list_users = []
        for _ in range(_count_users):
            _item_users = reader.tgread_object()
            _list_users.append(_item_users)
        _args['users'] = _list_users
        return cls(**_args)


class PhotosSlice(TLObject):
    """TL type: photos.photosSlice"""
    CONSTRUCTOR_ID = 0x15051f54
    SUBCLASS_OF_ID = 0x27cfb967

    def __init__(self, count: int, photos: List['TypePhoto'], users: List['TypeUser']):
        self.count = count
        self.photos = photos
        self.users = users

    def to_dict(self):
        return {
            '_': 'PhotosSlice',
            'count': self.count,
            'photos': self.photos,
            'users': self.users,
        }

    def _bytes(self) -> bytes:
        import io
        buf = io.BytesIO()
        buf.write(struct.pack('<I', self.CONSTRUCTOR_ID))
        buf.write(struct.pack('<i', self.count))
        buf.write(struct.pack('<i', 0x1cb5c415))  # vector id
        buf.write(struct.pack('<i', len(self.photos)))
        for item in self.photos:
            buf.write(bytes(self.item))
        buf.write(struct.pack('<i', 0x1cb5c415))  # vector id
        buf.write(struct.pack('<i', len(self.users)))
        for item in self.users:
            buf.write(bytes(self.item))
        return buf.getvalue()

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        _val_count = reader.read_int()
        _args['count'] = _val_count
        reader.read_int(signed=False)  # skip vector id
        _count_photos = reader.read_int()
        _list_photos = []
        for _ in range(_count_photos):
            _item_photos = reader.tgread_object()
            _list_photos.append(_item_photos)
        _args['photos'] = _list_photos
        reader.read_int(signed=False)  # skip vector id
        _count_users = reader.read_int()
        _list_users = []
        for _ in range(_count_users):
            _item_users = reader.tgread_object()
            _list_users.append(_item_users)
        _args['users'] = _list_users
        return cls(**_args)

