from ...tl.mtproto_request import MTProtoRequest


class MessageActionPaymentSentMe(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. Original .tl definition below.
    messageActionPaymentSentMe#8f31b327 flags:# currency:string total_amount:long payload:bytes info:flags.0?PaymentRequestedInfo shipping_option_id:flags.1?string charge:PaymentCharge = MessageAction"""

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

    def __init__(self, currency, total_amount, payload, charge, info=None, shipping_option_id=None):
        """
        :param currency: Telegram type: «string».
        :param total_amount: Telegram type: «long».
        :param payload: Telegram type: «bytes».
        :param info: Telegram type: «PaymentRequestedInfo».
        :param shipping_option_id: Telegram type: «string».
        :param charge: Telegram type: «PaymentCharge».

        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.currency = currency
        self.total_amount = total_amount
        self.payload = payload
        self.info = info
        self.shipping_option_id = shipping_option_id
        self.charge = charge

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

        writer.tgwrite_string(self.currency)
        writer.write_long(self.total_amount)
        writer.tgwrite_bytes(self.payload)
        if self.info:
            self.info.on_send(writer)

        if self.shipping_option_id:
            writer.tgwrite_string(self.shipping_option_id)

        self.charge.on_send(writer)

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

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

        self.currency = reader.tgread_string()
        self.total_amount = reader.read_long()
        self.payload = reader.tgread_bytes()
        if (flags & (1 << 0)) != 0:
            self.info = reader.tgread_object()

        if (flags & (1 << 1)) != 0:
            self.shipping_option_id = reader.tgread_string()

        self.charge = reader.tgread_object()

    def __repr__(self):
        return 'messageActionPaymentSentMe#8f31b327 flags:# currency:string total_amount:long payload:bytes info:flags.0?PaymentRequestedInfo shipping_option_id:flags.1?string charge:PaymentCharge = MessageAction'

    def __str__(self):
        return '(messageActionPaymentSentMe (ID: 0x8f31b327) = (currency={}, total_amount={}, payload={}, info={}, shipping_option_id={}, charge={}))'.format(str(self.currency), str(self.total_amount), str(self.payload), str(self.info), str(self.shipping_option_id), str(self.charge))
