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

namespace MyTelegram.Schema;

///<summary>
/// See <a href="https://corefork.telegram.org/constructor/inputInvoicePremiumGiftStars" />
///</summary>
[TlObject(0xdabab2ef)]
public sealed class TInputInvoicePremiumGiftStars : IInputInvoice
{
    public uint ConstructorId => 0xdabab2ef;
    public int Flags { get; set; }
    public MyTelegram.Schema.IInputUser UserId { get; set; }
    public int Months { get; set; }
    public MyTelegram.Schema.ITextWithEntities? Message { get; set; }

    public void ComputeFlag()
    {
        if (Message != null) { Flags = Flags.SetBit(0); }
    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(UserId);
        writer.Write(Months);
        if (Flags.IsBitSet(0)) { writer.Write(Message); }
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        UserId = buffer.Read<MyTelegram.Schema.IInputUser>();
        Months = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { Message = buffer.Read<MyTelegram.Schema.ITextWithEntities>(); }
    }
}