from ....tl.mtproto_request import MTProtoRequest


class PhoneCall(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. Original .tl definition below.
    phone.phoneCall#ec82e140 phone_call:PhoneCall users:Vector<User> = phone.PhoneCall"""

    # Telegram's constructor ID (and unique identifier) for this class
    constructor_id = 0xec82e140

    def __init__(self, phone_call, users):
        """
        :param phone_call: Telegram type: «PhoneCall».
        :param users: Telegram type: «User». Must be a list.

        Constructor for phone.PhoneCall: Instance of PhoneCall.
        """
        super().__init__()

        self.phone_call = phone_call
        self.users = users

    def on_send(self, writer):
        writer.write_int(PhoneCall.constructor_id, signed=False)
        self.phone_call.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 (all attributes are None)"""
        return PhoneCall(None, None)

    def on_response(self, reader):
        self.phone_call = reader.tgread_object()
        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 'phone.phoneCall#ec82e140 phone_call:PhoneCall users:Vector<User> = phone.PhoneCall'

    def __str__(self):
        return '(phone.phoneCall (ID: 0xec82e140) = (phone_call={}, users={}))'.format(str(self.phone_call), None if not self.users else [str(_) for _ in self.users])
