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

namespace MyTelegram.Schema;

///<summary>
/// <a href="https://corefork.telegram.org/api/saved-messages">Pinned saved dialogs »</a> were updated
/// See <a href="https://corefork.telegram.org/constructor/updatePinnedSavedDialogs" />
///</summary>
[TlObject(0x686c85a6)]
public sealed class TUpdatePinnedSavedDialogs : IUpdate
{
    public uint ConstructorId => 0x686c85a6;
    ///<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>
    /// New order of pinned saved dialogs
    ///</summary>
    public TVector<MyTelegram.Schema.IDialogPeer>? Order { get; set; }

    public void ComputeFlag()
    {
        if (Order?.Count > 0) { Flags = Flags.SetBit(0); }
    }

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

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { Order = buffer.Read<TVector<MyTelegram.Schema.IDialogPeer>>(); }
    }
}