from ...tl.mtproto_request import MTProtoRequest


class InputPaymentCredentials(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. Original .tl definition below.
    inputPaymentCredentials#3417d728 flags:# save:flags.0?true data:DataJSON = InputPaymentCredentials"""

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

    def __init__(self, data, save=None):
        """
        :param save: Telegram type: «true».
        :param data: Telegram type: «DataJSON».

        Constructor for InputPaymentCredentials: Instance of either InputPaymentCredentialsSaved, InputPaymentCredentials.
        """
        super().__init__()

        self.save = save
        self.data = data

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

        self.data.on_send(writer)

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

    def on_response(self, reader):
        flags = reader.read_int()

        if (flags & (1 << 0)) != 0:
            self.save = True  # Arbitrary not-None value, no need to read since it is a flag

        self.data = reader.tgread_object()

    def __repr__(self):
        return 'inputPaymentCredentials#3417d728 flags:# save:flags.0?true data:DataJSON = InputPaymentCredentials'

    def __str__(self):
        return '(inputPaymentCredentials (ID: 0x3417d728) = (save={}, data={}))'.format(str(self.save), str(self.data))
