from ....tl.mtproto_request import MTProtoRequest


class Authorizations(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. Original .tl definition below.
    account.authorizations#1250abde authorizations:Vector<Authorization> = account.Authorizations"""

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

    def __init__(self, authorizations):
        """
        :param authorizations: Telegram type: «Authorization». Must be a list.

        Constructor for account.Authorizations: Instance of Authorizations.
        """
        super().__init__()

        self.authorizations = authorizations

    def on_send(self, writer):
        writer.write_int(Authorizations.constructor_id, signed=False)
        writer.write_int(0x1cb5c415, signed=False)  # Vector's constructor ID
        writer.write_int(len(self.authorizations))
        for authorizations_item in self.authorizations:
            authorizations_item.on_send(writer)

    @staticmethod
    def empty():
        """Returns an "empty" instance (all attributes are None)"""
        return Authorizations(None)

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

    def __repr__(self):
        return 'account.authorizations#1250abde authorizations:Vector<Authorization> = account.Authorizations'

    def __str__(self):
        return '(account.authorizations (ID: 0x1250abde) = (authorizations={}))'.format(None if not self.authorizations else [str(_) for _ in self.authorizations])
