from ....tl.mtproto_request import MTProtoRequest


class SetBotShippingResultsRequest(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. Original .tl definition below.
    messages.setBotShippingResults#e5f672fa flags:# query_id:long error:flags.0?string shipping_options:flags.1?Vector<ShippingOption> = Bool"""

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

    def __init__(self, query_id, error=None, shipping_options=None):
        """
        :param query_id: Telegram type: «long».
        :param error: Telegram type: «string».
        :param shipping_options: Telegram type: «ShippingOption». Must be a list.

        :returns Bool: This type has no constructors.
        """
        super().__init__()
        self.result = None
        self.confirmed = True  # Confirmed by default

        self.query_id = query_id
        self.error = error
        self.shipping_options = shipping_options

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

        writer.write_long(self.query_id)
        if self.error:
            writer.tgwrite_string(self.error)

        if self.shipping_options:
            writer.write_int(0x1cb5c415, signed=False)  # Vector's constructor ID
            writer.write_int(len(self.shipping_options))
            for shipping_options_item in self.shipping_options:
                if shipping_options_item:
                    shipping_options_item.on_send(writer)

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

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

    def __repr__(self):
        return 'messages.setBotShippingResults#e5f672fa flags:# query_id:long error:flags.0?string shipping_options:flags.1?Vector<ShippingOption> = Bool'

    def __str__(self):
        return '(messages.setBotShippingResults (ID: 0xe5f672fa) = (query_id={}, error={}, shipping_options={}))'.format(str(self.query_id), str(self.error), None if not self.shipping_options else [str(_) for _ in self.shipping_options])
