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

namespace MyTelegram.Schema;

///<summary>
/// The <a href="https://corefork.telegram.org/api/forum#forum-topics">pinned topics</a> of a forum have changed.
/// See <a href="https://corefork.telegram.org/constructor/updateChannelPinnedTopics" />
///</summary>
[TlObject(0xfe198602)]
public sealed class TUpdateChannelPinnedTopics : IUpdate
{
    public uint ConstructorId => 0xfe198602;
    ///<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>
    /// Forum ID.
    ///</summary>
    public long ChannelId { get; set; }

    ///<summary>
    /// Ordered list containing the IDs of all pinned topics.
    ///</summary>
    public TVector<int>? 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);
        writer.Write(ChannelId);
        if (Flags.IsBitSet(0)) { writer.Write(Order); }
    }

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