from ...tl.tlobject import TLObject


class PaymentRequestedInfo(TLObject):
    """Class generated by TLObjects' generator. All changes will be ERASED. TL definition below.
    paymentRequestedInfo#909c3f94 flags:# name:flags.0?string phone:flags.1?string email:flags.2?string shipping_address:flags.3?PostAddress = PaymentRequestedInfo"""

    # Telegram's constructor (U)ID for this class
    constructor_id = 0x909c3f94
    # Also the ID of its resulting type for fast checks
    subclass_of_id = 0x8db03146

    def __init__(self, name=None, phone=None, email=None, shipping_address=None):
        """
        :param name: Telegram type: "string".
        :param phone: Telegram type: "string".
        :param email: Telegram type: "string".
        :param shipping_address: Telegram type: "PostAddress".

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

        self.name = name
        self.phone = phone
        self.email = email
        self.shipping_address = shipping_address

    def to_dict(self):
        return {
            'name': self.name,
            'phone': self.phone,
            'email': self.email,
            'shipping_address': None if self.shipping_address is None else self.shipping_address.to_dict(),
        }

    def on_send(self, writer):
        writer.write_int(PaymentRequestedInfo.constructor_id, signed=False)
        # Calculate the flags. This equals to those flag arguments which are NOT None
        flags = 0
        flags |= (1 << 0) if self.name else 0
        flags |= (1 << 1) if self.phone else 0
        flags |= (1 << 2) if self.email else 0
        flags |= (1 << 3) if self.shipping_address else 0
        writer.write_int(flags)

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

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

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

        if self.shipping_address:
            self.shipping_address.on_send(writer)

    @staticmethod
    def empty():
        """Returns an "empty" instance (attributes=None)"""
        return PaymentRequestedInfo(None, None, None, None)

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

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

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

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

        if (flags & (1 << 3)) != 0:
            self.shipping_address = reader.tgread_object()

    def __repr__(self):
        return 'paymentRequestedInfo#909c3f94 flags:# name:flags.0?string phone:flags.1?string email:flags.2?string shipping_address:flags.3?PostAddress = PaymentRequestedInfo'

    def __str__(self):
        return TLObject.pretty_format(self)

    def stringify(self):
        return TLObject.pretty_format(self, indent=0)
