// <auto-generated/>
// ReSharper disable All

namespace MyTelegram.Schema.Payments;

///<summary>
/// Represents a payment form, for payments to be using <a href="https://corefork.telegram.org/api/stars">Telegram Stars, see here »</a> for more info.
/// See <a href="https://corefork.telegram.org/constructor/payments.paymentFormStars" />
///</summary>
[TlObject(0x7bf6b15c)]
public sealed class TPaymentFormStars : IPaymentForm
{
    public uint ConstructorId => 0x7bf6b15c;
    ///<summary>
    /// Flags, see <a href="https://corefork.telegram.org/mtproto/TL-combinators#conditional-fields">TL conditional fields</a>
    ///</summary>
    public int Flags { get; set; }

    ///<summary>
    /// Form ID.
    ///</summary>
    public long FormId { get; set; }

    ///<summary>
    /// Bot ID.
    ///</summary>
    public long BotId { get; set; }

    ///<summary>
    /// Form title
    ///</summary>
    public string Title { get; set; }

    ///<summary>
    /// Description
    ///</summary>
    public string Description { get; set; }

    ///<summary>
    /// Product photo
    /// See <a href="https://corefork.telegram.org/type/WebDocument" />
    ///</summary>
    public MyTelegram.Schema.IWebDocument? Photo { get; set; }

    ///<summary>
    /// Invoice
    /// See <a href="https://corefork.telegram.org/type/Invoice" />
    ///</summary>
    public MyTelegram.Schema.IInvoice Invoice { get; set; }

    ///<summary>
    /// Info about users mentioned in the other fields.
    ///</summary>
    public TVector<MyTelegram.Schema.IUser> Users { get; set; }

    public void ComputeFlag()
    {
        if (Photo != null) { Flags = Flags.SetBit(5); }

    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(FormId);
        writer.Write(BotId);
        writer.Write(Title);
        writer.Write(Description);
        if (Flags.IsBitSet(5)) { writer.Write(Photo); }
        writer.Write(Invoice);
        writer.Write(Users);
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        FormId = buffer.ReadInt64();
        BotId = buffer.ReadInt64();
        Title = buffer.ReadString();
        Description = buffer.ReadString();
        if (Flags.IsBitSet(5)) { Photo = buffer.Read<MyTelegram.Schema.IWebDocument>(); }
        Invoice = buffer.Read<MyTelegram.Schema.IInvoice>();
        Users = buffer.Read<TVector<MyTelegram.Schema.IUser>>();
    }
}