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

namespace MyTelegram.Schema.Payments;

///<summary>
/// Receipt for <a href="https://corefork.telegram.org/api/stars">payment made using Telegram Stars</a>.
/// See <a href="https://corefork.telegram.org/constructor/payments.paymentReceiptStars" />
///</summary>
[TlObject(0xdabbf83a)]
public sealed class TPaymentReceiptStars : IPaymentReceipt
{
    public uint ConstructorId => 0xdabbf83a;
    ///<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>
    /// Date of generation
    ///</summary>
    public int Date { get; set; }

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

    ///<summary>
    /// 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>
    /// Currency, always <code>XTR</code>.
    ///</summary>
    public string Currency { get; set; }

    ///<summary>
    /// Amount of <a href="https://corefork.telegram.org/api/stars">Telegram Stars</a>.
    ///</summary>
    public long TotalAmount { get; set; }

    ///<summary>
    /// Transaction ID
    ///</summary>
    public string TransactionId { 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(2); }

    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(Date);
        writer.Write(BotId);
        writer.Write(Title);
        writer.Write(Description);
        if (Flags.IsBitSet(2)) { writer.Write(Photo); }
        writer.Write(Invoice);
        writer.Write(Currency);
        writer.Write(TotalAmount);
        writer.Write(TransactionId);
        writer.Write(Users);
    }

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