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

namespace MyTelegram.Schema.Payments;

///<summary>
/// See <a href="https://corefork.telegram.org/method/payments.getSavedStarGifts" />
///</summary>
[TlObject(0x23830de9)]
public sealed class RequestGetSavedStarGifts : IRequest<MyTelegram.Schema.Payments.ISavedStarGifts>
{
    public uint ConstructorId => 0x23830de9;
    public int Flags { get; set; }
    public bool ExcludeUnsaved { get; set; }
    public bool ExcludeSaved { get; set; }
    public bool ExcludeUnlimited { get; set; }
    public bool ExcludeLimited { get; set; }
    public bool ExcludeUnique { get; set; }
    public bool SortByValue { get; set; }
    public int? CollectionId { get; set; }
    public bool ExcludeUpgradable { get; set; }
    public bool ExcludeUnupgradable { get; set; }
    public MyTelegram.Schema.IInputPeer Peer { get; set; }
    public string Offset { get; set; }
    public int Limit { get; set; }

    public void ComputeFlag()
    {
        if (ExcludeUnsaved) { Flags = Flags.SetBit(0); }
        if (ExcludeSaved) { Flags = Flags.SetBit(1); }
        if (ExcludeUnlimited) { Flags = Flags.SetBit(2); }
        if (ExcludeLimited) { Flags = Flags.SetBit(3); }
        if (ExcludeUnique) { Flags = Flags.SetBit(4); }
        if (SortByValue) { Flags = Flags.SetBit(5); }
        if (CollectionId.HasValue) { Flags = Flags.SetBit(6); }
        if (ExcludeUpgradable) { Flags = Flags.SetBit(7); }
        if (ExcludeUnupgradable) { Flags = Flags.SetBit(8); }
    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(Peer);
        if (CollectionId.HasValue) { writer.Write(CollectionId.Value); }
        writer.Write(Offset);
        writer.Write(Limit);
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { ExcludeUnsaved = true; }
        if (Flags.IsBitSet(1)) { ExcludeSaved = true; }
        if (Flags.IsBitSet(2)) { ExcludeUnlimited = true; }
        if (Flags.IsBitSet(3)) { ExcludeLimited = true; }
        if (Flags.IsBitSet(4)) { ExcludeUnique = true; }
        if (Flags.IsBitSet(5)) { SortByValue = true; }
        if (Flags.IsBitSet(6)) { CollectionId = buffer.ReadInt32(); }
        if (Flags.IsBitSet(7)) { ExcludeUpgradable = true; }
        if (Flags.IsBitSet(8)) { ExcludeUnupgradable = true; }
        Peer = buffer.Read<MyTelegram.Schema.IInputPeer>();
        Offset = buffer.ReadString();
        Limit = buffer.ReadInt32();
    }
}
