// <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/channelAdminLogEventActionPinTopic" />
///</summary>
[TlObject(0x5d8d353b)]
public sealed class TChannelAdminLogEventActionPinTopic : IChannelAdminLogEventAction
{
    public uint ConstructorId => 0x5d8d353b;
    ///<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>
    /// Previous topic information
    /// See <a href="https://corefork.telegram.org/type/ForumTopic" />
    ///</summary>
    public MyTelegram.Schema.IForumTopic? PrevTopic { get; set; }

    ///<summary>
    /// New topic information
    /// See <a href="https://corefork.telegram.org/type/ForumTopic" />
    ///</summary>
    public MyTelegram.Schema.IForumTopic? NewTopic { get; set; }

    public void ComputeFlag()
    {
        if (PrevTopic != null) { Flags = Flags.SetBit(0); }
        if (NewTopic != null) { Flags = Flags.SetBit(1); }
    }

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

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { PrevTopic = buffer.Read<MyTelegram.Schema.IForumTopic>(); }
        if (Flags.IsBitSet(1)) { NewTopic = buffer.Read<MyTelegram.Schema.IForumTopic>(); }
    }
}