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

namespace MyTelegram.Schema.Payments;

///<summary>
/// See <a href="https://corefork.telegram.org/constructor/payments.savedStarGifts" />
///</summary>
[TlObject(0x95f389b1)]
public sealed class TSavedStarGifts : ISavedStarGifts
{
    public uint ConstructorId => 0x95f389b1;
    public int Flags { get; set; }
    public int Count { get; set; }
    public bool? ChatNotificationsEnabled { get; set; }
    public TVector<MyTelegram.Schema.ISavedStarGift> Gifts { get; set; }
    public string? NextOffset { get; set; }
    public TVector<MyTelegram.Schema.IChat> Chats { get; set; }
    public TVector<MyTelegram.Schema.IUser> Users { get; set; }

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

    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(Count);
        if (Flags.IsBitSet(1)) { writer.Write(ChatNotificationsEnabled.Value); }
        writer.Write(Gifts);
        if (Flags.IsBitSet(0)) { writer.Write(NextOffset); }
        writer.Write(Chats);
        writer.Write(Users);
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        Count = buffer.ReadInt32();
        if (Flags.IsBitSet(1)) { ChatNotificationsEnabled = buffer.Read(); }
        Gifts = buffer.Read<TVector<MyTelegram.Schema.ISavedStarGift>>();
        if (Flags.IsBitSet(0)) { NextOffset = buffer.ReadString(); }
        Chats = buffer.Read<TVector<MyTelegram.Schema.IChat>>();
        Users = buffer.Read<TVector<MyTelegram.Schema.IUser>>();
    }
}