from ...tl.mtproto_request import MTProtoRequest


class MessageActionChatCreate(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. TL definition below.
    messageActionChatCreate#a6638b9a title:string users:Vector<int> = MessageAction"""

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

    def __init__(self, title, users):
        """
        :param title: Telegram type: "string".
        :param users: Telegram type: "int". Must be a list.

        Constructor for MessageAction: Instance of either MessageActionEmpty, MessageActionChatCreate, MessageActionChatEditTitle, MessageActionChatEditPhoto, MessageActionChatDeletePhoto, MessageActionChatAddUser, MessageActionChatDeleteUser, MessageActionChatJoinedByLink, MessageActionChannelCreate, MessageActionChatMigrateTo, MessageActionChannelMigrateFrom, MessageActionPinMessage, MessageActionHistoryClear, MessageActionGameScore, MessageActionPaymentSentMe, MessageActionPaymentSent, MessageActionPhoneCall.
        """
        super().__init__()

        self.title = title
        self.users = users

    def to_dict(self):
        return {
            'title': self.title,
            'users': [] if self.users is None else self.users[:],
        }

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

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

    def on_response(self, reader):
        self.title = reader.tgread_string()
        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.read_int()
            self.users.append(users_item)

    def __repr__(self):
        return 'messageActionChatCreate#a6638b9a title:string users:Vector<int> = MessageAction'

    def __str__(self):
        return '(messageActionChatCreate (ID: 0xa6638b9a) = (title={}, users={}))'.format(str(self.title), None if not self.users else [str(_) for _ in self.users])
