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

namespace MyTelegram.Schema;

///<summary>
/// A dialog was pinned/unpinned
/// See <a href="https://corefork.telegram.org/constructor/updateDialogPinned" />
///</summary>
[TlObject(0x6e6fe51c)]
public sealed class TUpdateDialogPinned : IUpdate
{
    public uint ConstructorId => 0x6e6fe51c;
    ///<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>
    /// Whether the dialog was pinned
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Pinned { 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>
    /// The dialog
    /// See <a href="https://corefork.telegram.org/type/DialogPeer" />
    ///</summary>
    public MyTelegram.Schema.IDialogPeer Peer { get; set; }

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

    }

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

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