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

namespace MyTelegram.Schema.Channels;

///<summary>
/// Get the admin log of a <a href="https://corefork.telegram.org/api/channel">channel/supergroup</a>
/// <para>Possible errors</para>
/// Code Type Description
/// 400 CHANNEL_INVALID The provided channel is invalid.
/// 406 CHANNEL_PRIVATE You haven't joined this channel/supergroup.
/// 403 CHAT_ADMIN_REQUIRED You must be an admin in this chat to do this.
/// 403 CHAT_WRITE_FORBIDDEN You can't write in this chat.
/// 400 MSG_ID_INVALID Invalid message ID provided.
/// See <a href="https://corefork.telegram.org/method/channels.getAdminLog" />
///</summary>
[TlObject(0x33ddf480)]
public sealed class RequestGetAdminLog : IRequest<MyTelegram.Schema.Channels.IAdminLogResults>
{
    public uint ConstructorId => 0x33ddf480;
    ///<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
    /// See <a href="https://corefork.telegram.org/type/InputChannel" />
    ///</summary>
    public MyTelegram.Schema.IInputChannel Channel { get; set; }

    ///<summary>
    /// Search query, can be empty
    ///</summary>
    public string Q { get; set; }

    ///<summary>
    /// Event filter
    /// See <a href="https://corefork.telegram.org/type/ChannelAdminLogEventsFilter" />
    ///</summary>
    public MyTelegram.Schema.IChannelAdminLogEventsFilter? EventsFilter { get; set; }

    ///<summary>
    /// Only show events from these admins
    ///</summary>
    public TVector<MyTelegram.Schema.IInputUser>? Admins { get; set; }

    ///<summary>
    /// Maximum ID of message to return (see <a href="https://corefork.telegram.org/api/offsets">pagination</a>)
    ///</summary>
    public long MaxId { get; set; }

    ///<summary>
    /// Minimum ID of message to return (see <a href="https://corefork.telegram.org/api/offsets">pagination</a>)
    ///</summary>
    public long MinId { get; set; }

    ///<summary>
    /// Maximum number of results to return, <a href="https://corefork.telegram.org/api/offsets">see pagination</a>
    ///</summary>
    public int Limit { get; set; }

    public void ComputeFlag()
    {
        if (EventsFilter != null) { Flags = Flags.SetBit(0); }
        if (Admins?.Count > 0) { Flags = Flags.SetBit(1); }

    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(Channel);
        writer.Write(Q);
        if (Flags.IsBitSet(0)) { writer.Write(EventsFilter); }
        if (Flags.IsBitSet(1)) { writer.Write(Admins); }
        writer.Write(MaxId);
        writer.Write(MinId);
        writer.Write(Limit);
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        Channel = buffer.Read<MyTelegram.Schema.IInputChannel>();
        Q = buffer.ReadString();
        if (Flags.IsBitSet(0)) { EventsFilter = buffer.Read<MyTelegram.Schema.IChannelAdminLogEventsFilter>(); }
        if (Flags.IsBitSet(1)) { Admins = buffer.Read<TVector<MyTelegram.Schema.IInputUser>>(); }
        MaxId = buffer.ReadInt64();
        MinId = buffer.ReadInt64();
        Limit = buffer.ReadInt32();
    }
}
