"""File generated by TLObjects' generator. All changes will be ERASED"""
from ...tl.tlobject import TLObject


class PaymentForm(TLObject):
    constructor_id = 0x3f56aea3
    subclass_of_id = 0xa0483f19

    def __init__(self, bot_id, invoice, provider_id, url, users, can_save_credentials=None, password_missing=None, native_provider=None, native_params=None, saved_info=None, saved_credentials=None):
        """
        :param can_save_credentials: Telegram type: "true".
        :param password_missing: Telegram type: "true".
        :param bot_id: Telegram type: "int".
        :param invoice: Telegram type: "Invoice".
        :param provider_id: Telegram type: "int".
        :param url: Telegram type: "string".
        :param native_provider: Telegram type: "string".
        :param native_params: Telegram type: "DataJSON".
        :param saved_info: Telegram type: "PaymentRequestedInfo".
        :param saved_credentials: Telegram type: "PaymentSavedCredentials".
        :param users: Telegram type: "User". Must be a list.

        Constructor for payments.PaymentForm: Instance of PaymentForm.
        """
        super().__init__()

        self.can_save_credentials = can_save_credentials
        self.password_missing = password_missing
        self.bot_id = bot_id
        self.invoice = invoice
        self.provider_id = provider_id
        self.url = url
        self.native_provider = native_provider
        self.native_params = native_params
        self.saved_info = saved_info
        self.saved_credentials = saved_credentials
        self.users = users

    def to_dict(self):
        return {
            'can_save_credentials': self.can_save_credentials,
            'password_missing': self.password_missing,
            'bot_id': self.bot_id,
            'invoice': None if self.invoice is None else self.invoice.to_dict(),
            'provider_id': self.provider_id,
            'url': self.url,
            'native_provider': self.native_provider,
            'native_params': None if self.native_params is None else self.native_params.to_dict(),
            'saved_info': None if self.saved_info is None else self.saved_info.to_dict(),
            'saved_credentials': None if self.saved_credentials is None else self.saved_credentials.to_dict(),
            'users': [] if self.users is None else [None if x is None else x.to_dict() for x in self.users],
        }

    def on_send(self, writer):
        writer.write_int(PaymentForm.constructor_id, signed=False)
        flags = 0
        flags |= (1 << 2) if self.can_save_credentials else 0
        flags |= (1 << 3) if self.password_missing else 0
        flags |= (1 << 4) if self.native_provider else 0
        flags |= (1 << 4) if self.native_params else 0
        flags |= (1 << 0) if self.saved_info else 0
        flags |= (1 << 1) if self.saved_credentials else 0
        writer.write_int(flags)

        writer.write_int(self.bot_id)
        self.invoice.on_send(writer)
        writer.write_int(self.provider_id)
        writer.tgwrite_string(self.url)
        if self.native_provider:
            writer.tgwrite_string(self.native_provider)

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

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

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

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

    @staticmethod
    def empty():
        return PaymentForm(None, None, None, None, None, None, None, None, None, None, None)

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

        if (flags & (1 << 2)) != 0:
            self.can_save_credentials = True

        if (flags & (1 << 3)) != 0:
            self.password_missing = True

        self.bot_id = reader.read_int()
        self.invoice = reader.tgread_object()
        self.provider_id = reader.read_int()
        self.url = reader.tgread_string()
        if (flags & (1 << 4)) != 0:
            self.native_provider = reader.tgread_string()

        if (flags & (1 << 4)) != 0:
            self.native_params = reader.tgread_object()

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

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

        reader.read_int()
        self.users = []
        _len = reader.read_int()
        for _ in range(_len):
            _x = reader.tgread_object()
            self.users.append(_x)

    def __repr__(self):
        return 'payments.paymentForm#3f56aea3 flags:# can_save_credentials:flags.2?true password_missing:flags.3?true bot_id:int invoice:Invoice provider_id:int url:string native_provider:flags.4?string native_params:flags.4?DataJSON saved_info:flags.0?PaymentRequestedInfo saved_credentials:flags.1?PaymentSavedCredentials users:Vector<User> = payments.PaymentForm'

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

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



class PaymentReceipt(TLObject):
    constructor_id = 0x500911e1
    subclass_of_id = 0x590093c9

    def __init__(self, date, bot_id, invoice, provider_id, currency, total_amount, credentials_title, users, info=None, shipping=None):
        """
        :param date: Telegram type: "date".
        :param bot_id: Telegram type: "int".
        :param invoice: Telegram type: "Invoice".
        :param provider_id: Telegram type: "int".
        :param info: Telegram type: "PaymentRequestedInfo".
        :param shipping: Telegram type: "ShippingOption".
        :param currency: Telegram type: "string".
        :param total_amount: Telegram type: "long".
        :param credentials_title: Telegram type: "string".
        :param users: Telegram type: "User". Must be a list.

        Constructor for payments.PaymentReceipt: Instance of PaymentReceipt.
        """
        super().__init__()

        self.date = date
        self.bot_id = bot_id
        self.invoice = invoice
        self.provider_id = provider_id
        self.info = info
        self.shipping = shipping
        self.currency = currency
        self.total_amount = total_amount
        self.credentials_title = credentials_title
        self.users = users

    def to_dict(self):
        return {
            'date': self.date,
            'bot_id': self.bot_id,
            'invoice': None if self.invoice is None else self.invoice.to_dict(),
            'provider_id': self.provider_id,
            'info': None if self.info is None else self.info.to_dict(),
            'shipping': None if self.shipping is None else self.shipping.to_dict(),
            'currency': self.currency,
            'total_amount': self.total_amount,
            'credentials_title': self.credentials_title,
            'users': [] if self.users is None else [None if x is None else x.to_dict() for x in self.users],
        }

    def on_send(self, writer):
        writer.write_int(PaymentReceipt.constructor_id, signed=False)
        flags = 0
        flags |= (1 << 0) if self.info else 0
        flags |= (1 << 1) if self.shipping else 0
        writer.write_int(flags)

        writer.tgwrite_date(self.date)
        writer.write_int(self.bot_id)
        self.invoice.on_send(writer)
        writer.write_int(self.provider_id)
        if self.info:
            self.info.on_send(writer)

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

        writer.tgwrite_string(self.currency)
        writer.write_long(self.total_amount)
        writer.tgwrite_string(self.credentials_title)
        writer.write_int(0x1cb5c415, signed=False)  # Vector's constructor ID
        writer.write_int(len(self.users))
        for _x in self.users:
            _x.on_send(writer)

    @staticmethod
    def empty():
        return PaymentReceipt(None, None, None, None, None, None, None, None, None, None)

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

        self.date = reader.tgread_date()
        self.bot_id = reader.read_int()
        self.invoice = reader.tgread_object()
        self.provider_id = reader.read_int()
        if (flags & (1 << 0)) != 0:
            self.info = reader.tgread_object()

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

        self.currency = reader.tgread_string()
        self.total_amount = reader.read_long()
        self.credentials_title = reader.tgread_string()
        reader.read_int()
        self.users = []
        _len = reader.read_int()
        for _ in range(_len):
            _x = reader.tgread_object()
            self.users.append(_x)

    def __repr__(self):
        return 'payments.paymentReceipt#500911e1 flags:# date:int bot_id:int invoice:Invoice provider_id:int info:flags.0?PaymentRequestedInfo shipping:flags.1?ShippingOption currency:string total_amount:long credentials_title:string users:Vector<User> = payments.PaymentReceipt'

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

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



class PaymentResult(TLObject):
    constructor_id = 0x4e5f810d
    subclass_of_id = 0x8ae16a9d

    def __init__(self, updates):
        """
        :param updates: Telegram type: "Updates".

        Constructor for payments.PaymentResult: Instance of either PaymentResult, PaymentVerficationNeeded.
        """
        super().__init__()

        self.updates = updates

    def to_dict(self):
        return {
            'updates': None if self.updates is None else self.updates.to_dict(),
        }

    def on_send(self, writer):
        writer.write_int(PaymentResult.constructor_id, signed=False)
        self.updates.on_send(writer)

    @staticmethod
    def empty():
        return PaymentResult(None)

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

    def __repr__(self):
        return 'payments.paymentResult#4e5f810d updates:Updates = payments.PaymentResult'

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

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



class PaymentVerficationNeeded(TLObject):
    constructor_id = 0x6b56b921
    subclass_of_id = 0x8ae16a9d

    def __init__(self, url):
        """
        :param url: Telegram type: "string".

        Constructor for payments.PaymentResult: Instance of either PaymentResult, PaymentVerficationNeeded.
        """
        super().__init__()

        self.url = url

    def to_dict(self):
        return {
            'url': self.url,
        }

    def on_send(self, writer):
        writer.write_int(PaymentVerficationNeeded.constructor_id, signed=False)
        writer.tgwrite_string(self.url)

    @staticmethod
    def empty():
        return PaymentVerficationNeeded(None)

    def on_response(self, reader):
        self.url = reader.tgread_string()

    def __repr__(self):
        return 'payments.paymentVerficationNeeded#6b56b921 url:string = payments.PaymentResult'

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

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



class SavedInfo(TLObject):
    constructor_id = 0xfb8fe43c
    subclass_of_id = 0xad3cf146

    def __init__(self, has_saved_credentials=None, saved_info=None):
        """
        :param has_saved_credentials: Telegram type: "true".
        :param saved_info: Telegram type: "PaymentRequestedInfo".

        Constructor for payments.SavedInfo: Instance of SavedInfo.
        """
        super().__init__()

        self.has_saved_credentials = has_saved_credentials
        self.saved_info = saved_info

    def to_dict(self):
        return {
            'has_saved_credentials': self.has_saved_credentials,
            'saved_info': None if self.saved_info is None else self.saved_info.to_dict(),
        }

    def on_send(self, writer):
        writer.write_int(SavedInfo.constructor_id, signed=False)
        flags = 0
        flags |= (1 << 1) if self.has_saved_credentials else 0
        flags |= (1 << 0) if self.saved_info else 0
        writer.write_int(flags)

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

    @staticmethod
    def empty():
        return SavedInfo(None, None)

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

        if (flags & (1 << 1)) != 0:
            self.has_saved_credentials = True

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

    def __repr__(self):
        return 'payments.savedInfo#fb8fe43c flags:# has_saved_credentials:flags.1?true saved_info:flags.0?PaymentRequestedInfo = payments.SavedInfo'

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

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



class ValidatedRequestedInfo(TLObject):
    constructor_id = 0xd1451883
    subclass_of_id = 0x8f8044b7

    def __init__(self, id=None, shipping_options=None):
        """
        :param id: Telegram type: "string".
        :param shipping_options: Telegram type: "ShippingOption". Must be a list.

        Constructor for payments.ValidatedRequestedInfo: Instance of ValidatedRequestedInfo.
        """
        super().__init__()

        self.id = id
        self.shipping_options = shipping_options

    def to_dict(self):
        return {
            'id': self.id,
            'shipping_options': [] if self.shipping_options is None else [None if x is None else x.to_dict() for x in self.shipping_options],
        }

    def on_send(self, writer):
        writer.write_int(ValidatedRequestedInfo.constructor_id, signed=False)
        flags = 0
        flags |= (1 << 0) if self.id else 0
        flags |= (1 << 1) if self.shipping_options else 0
        writer.write_int(flags)

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

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

    @staticmethod
    def empty():
        return ValidatedRequestedInfo(None, None)

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

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

        if (flags & (1 << 1)) != 0:
            reader.read_int()
            self.shipping_options = []
            _len = reader.read_int()
            for _ in range(_len):
                _x = reader.tgread_object()
                self.shipping_options.append(_x)

    def __repr__(self):
        return 'payments.validatedRequestedInfo#d1451883 flags:# id:flags.0?string shipping_options:flags.1?Vector<ShippingOption> = payments.ValidatedRequestedInfo'

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

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

