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

namespace MyTelegram.Schema.Messages;

///<summary>
/// Reorder pinned dialogs
/// <para>Possible errors</para>
/// Code Type Description
/// 400 PEER_ID_INVALID The provided peer id is invalid.
/// See <a href="https://corefork.telegram.org/method/messages.reorderPinnedDialogs" />
///</summary>
[TlObject(0x3b1adf37)]
public sealed class RequestReorderPinnedDialogs : IRequest<IBool>
{
    public uint ConstructorId => 0x3b1adf37;
    ///<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>
    /// If set, dialogs pinned server-side but not present in the <code>order</code> field will be unpinned.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Force { 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 dialog order
    ///</summary>
    public TVector<MyTelegram.Schema.IInputDialogPeer> Order { get; set; }

    public void ComputeFlag()
    {
        if (Force) { Flags = Flags.SetBit(0); }

    }

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

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