from ...tl.mtproto_request import MTProtoRequest


class ShippingOption(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. Original .tl definition below.
    shippingOption#b6213cdf id:string title:string prices:Vector<LabeledPrice> = ShippingOption"""

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

    def __init__(self, id, title, prices):
        """
        :param id: Telegram type: «string».
        :param title: Telegram type: «string».
        :param prices: Telegram type: «LabeledPrice». Must be a list.

        Constructor for ShippingOption: Instance of ShippingOption.
        """
        super().__init__()

        self.id = id
        self.title = title
        self.prices = prices

    def on_send(self, writer):
        writer.write_int(ShippingOption.constructor_id, signed=False)
        writer.tgwrite_string(self.id)
        writer.tgwrite_string(self.title)
        writer.write_int(0x1cb5c415, signed=False)  # Vector's constructor ID
        writer.write_int(len(self.prices))
        for prices_item in self.prices:
            prices_item.on_send(writer)

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

    def on_response(self, reader):
        self.id = reader.tgread_string()
        self.title = reader.tgread_string()
        reader.read_int()  # Vector's constructor ID
        self.prices = []  # Initialize an empty list
        prices_len = reader.read_int()
        for _ in range(prices_len):
            prices_item = reader.tgread_object()
            self.prices.append(prices_item)

    def __repr__(self):
        return 'shippingOption#b6213cdf id:string title:string prices:Vector<LabeledPrice> = ShippingOption'

    def __str__(self):
        return '(shippingOption (ID: 0xb6213cdf) = (id={}, title={}, prices={}))'.format(str(self.id), str(self.title), None if not self.prices else [str(_) for _ in self.prices])
