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

namespace MyTelegram.Schema.Channels;

///<summary>
/// Get <a href="https://corefork.telegram.org/api/forum">topics of a forum</a>
/// <para>Possible errors</para>
/// Code Type Description
/// 400 CHANNEL_FORUM_MISSING This supergroup is not a forum.
/// 400 CHANNEL_INVALID The provided channel is invalid.
/// 400 CHANNEL_PRIVATE You haven't joined this channel/supergroup.
/// See <a href="https://corefork.telegram.org/method/channels.getForumTopics" />
///</summary>
[TlObject(0xde560d1)]
public sealed class RequestGetForumTopics : IRequest<MyTelegram.Schema.Messages.IForumTopics>
{
    public uint ConstructorId => 0xde560d1;
    ///<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>
    /// Supergroup
    /// See <a href="https://corefork.telegram.org/type/InputChannel" />
    ///</summary>
    public MyTelegram.Schema.IInputChannel Channel { get; set; }

    ///<summary>
    /// Search query
    ///</summary>
    public string? Q { get; set; }

    ///<summary>
    /// <a href="https://corefork.telegram.org/api/offsets">Offsets for pagination, for more info click here</a>, date of the last message of the last found topic. Use 0 or any date in the future to get results from the last topic.
    ///</summary>
    public int OffsetDate { get; set; }

    ///<summary>
    /// <a href="https://corefork.telegram.org/api/offsets">Offsets for pagination, for more info click here</a>, ID of the last message of the last found topic (or initially <code>0</code>).
    ///</summary>
    public int OffsetId { get; set; }

    ///<summary>
    /// <a href="https://corefork.telegram.org/api/offsets">Offsets for pagination, for more info click here</a>, ID of the last found topic (or initially <code>0</code>).
    ///</summary>
    public int OffsetTopic { get; set; }

    ///<summary>
    /// Maximum number of results to return, <a href="https://corefork.telegram.org/api/offsets">see pagination</a>. For optimal performance, the number of returned topics is chosen by the server and can be smaller than the specified limit.
    ///</summary>
    public int Limit { get; set; }

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

    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(Channel);
        if (Flags.IsBitSet(0)) { writer.Write(Q); }
        writer.Write(OffsetDate);
        writer.Write(OffsetId);
        writer.Write(OffsetTopic);
        writer.Write(Limit);
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        Channel = buffer.Read<MyTelegram.Schema.IInputChannel>();
        if (Flags.IsBitSet(0)) { Q = buffer.ReadString(); }
        OffsetDate = buffer.ReadInt32();
        OffsetId = buffer.ReadInt32();
        OffsetTopic = buffer.ReadInt32();
        Limit = buffer.ReadInt32();
    }
}
