from telethon.tl.mtproto_request import MTProtoRequest


class SendConfirmPhoneCodeRequest(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. Original .tl definition below.
    account.sendConfirmPhoneCode#1516d7bd flags:None allow_flashcall:flags.0?true hash:string current_number:flags.0?Bool = auth.SentCode"""

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

    def __init__(self, hash, allow_flashcall=None, current_number=None):
        """
        :param allow_flashcall: Telegram type: «true».
        :param hash: Telegram type: «string».
        :param current_number: Telegram type: «Bool».
        """
        super().__init__()
        self.result = None
        self.confirmed = True  # Confirmed by default

        self.allow_flashcall = allow_flashcall
        self.hash = hash
        self.current_number = current_number

    def on_send(self, writer):
        writer.write_int(SendConfirmPhoneCodeRequest.constructor_id, signed=False)
        # Calculate the flags. This equals to those flag arguments which are NOT None
        flags = 0
        flags |= (1 << 0) if self.allow_flashcall else 0
        flags |= (1 << 0) if self.current_number else 0
        writer.write_int(flags)

        writer.tgwrite_string(self.hash)
        if self.current_number:
            writer.tgwrite_bool(self.current_number)

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

    def on_response(self, reader):
        self.result = reader.tgread_object()

    def __repr__(self):
        return 'account.sendConfirmPhoneCode#1516d7bd flags:None allow_flashcall:flags.0?true hash:string current_number:flags.0?Bool = auth.SentCode'

    def __str__(self):
        return '(account.sendConfirmPhoneCode (ID: 0x1516d7bd) = (allow_flashcall={}, hash={}, current_number={}))'.format(str(self.allow_flashcall), str(self.hash), str(self.current_number))
