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

namespace MyTelegram.Schema;

///<summary>
/// A user is typing in a <a href="https://corefork.telegram.org/api/channel">supergroup, channel</a> or <a href="https://corefork.telegram.org/api/threads">message thread</a>
/// See <a href="https://corefork.telegram.org/constructor/updateChannelUserTyping" />
///</summary>
[TlObject(0x8c88c923)]
public sealed class TUpdateChannelUserTyping : IUpdate
{
    public uint ConstructorId => 0x8c88c923;
    ///<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>
    /// Channel ID
    ///</summary>
    public long ChannelId { get; set; }

    ///<summary>
    /// <a href="https://corefork.telegram.org/api/threads">Thread ID</a>
    ///</summary>
    public int? TopMsgId { get; set; }

    ///<summary>
    /// The peer that is typing
    /// See <a href="https://corefork.telegram.org/type/Peer" />
    ///</summary>
    public MyTelegram.Schema.IPeer FromId { get; set; }

    ///<summary>
    /// Whether the user is typing, sending a media or doing something else
    /// See <a href="https://corefork.telegram.org/type/SendMessageAction" />
    ///</summary>
    public MyTelegram.Schema.ISendMessageAction Action { get; set; }

    public void ComputeFlag()
    {
        if (/*TopMsgId != 0 && */TopMsgId.HasValue) { 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(TopMsgId.Value); }
        writer.Write(FromId);
        writer.Write(Action);
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        ChannelId = buffer.ReadInt64();
        if (Flags.IsBitSet(0)) { TopMsgId = buffer.ReadInt32(); }
        FromId = buffer.Read<MyTelegram.Schema.IPeer>();
        Action = buffer.Read<MyTelegram.Schema.ISendMessageAction>();
    }
}