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

namespace MyTelegram.Schema;

///<summary>
/// A <a href="https://corefork.telegram.org/api/forum#forum-topics">forum topic »</a> was pinned or unpinned.
/// See <a href="https://corefork.telegram.org/constructor/updateChannelPinnedTopic" />
///</summary>
[TlObject(0x192efbe3)]
public sealed class TUpdateChannelPinnedTopic : IUpdate
{
    public uint ConstructorId => 0x192efbe3;
    ///<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 topic was pinned or unpinned
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Pinned { get; set; }

    ///<summary>
    /// The forum ID
    ///</summary>
    public long ChannelId { get; set; }

    ///<summary>
    /// The topic ID
    ///</summary>
    public int TopicId { get; set; }

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

    }

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

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { Pinned = true; }
        ChannelId = buffer.ReadInt64();
        TopicId = buffer.ReadInt32();
    }
}