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

namespace MyTelegram.Schema;

///<summary>
/// Filter for getting only certain types of channel messages
/// See <a href="https://corefork.telegram.org/constructor/channelMessagesFilter" />
///</summary>
[TlObject(0xcd77d957)]
public sealed class TChannelMessagesFilter : IChannelMessagesFilter
{
    public uint ConstructorId => 0xcd77d957;
    ///<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 to exclude new messages from the search
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool ExcludeNewMessages { get; set; }

    ///<summary>
    /// A range of messages to fetch
    ///</summary>
    public TVector<MyTelegram.Schema.IMessageRange> Ranges { get; set; }

    public void ComputeFlag()
    {
        if (ExcludeNewMessages) { Flags = Flags.SetBit(1); }

    }

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

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(1)) { ExcludeNewMessages = true; }
        Ranges = buffer.Read<TVector<MyTelegram.Schema.IMessageRange>>();
    }
}