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

namespace MyTelegram.Schema;

///<summary>
/// Pinned dialogs were updated
/// See <a href="https://corefork.telegram.org/constructor/updatePinnedDialogs" />
///</summary>
[TlObject(0xfa0f3ca2)]
public sealed class TUpdatePinnedDialogs : IUpdate
{
    public uint ConstructorId => 0xfa0f3ca2;
    ///<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>
    /// <a href="https://corefork.telegram.org/api/folders#peer-folders">Peer folder ID, for more info click here</a>
    ///</summary>
    public int? FolderId { get; set; }

    ///<summary>
    /// New order of pinned dialogs
    ///</summary>
    public TVector<MyTelegram.Schema.IDialogPeer>? Order { get; set; }

    public void ComputeFlag()
    {
        if (/*FolderId != 0 && */FolderId.HasValue) { Flags = Flags.SetBit(1); }
        if (Order?.Count > 0) { Flags = Flags.SetBit(0); }
    }

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

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