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

namespace MyTelegram.Schema.Messages;

///<summary>
/// Get info about the users that joined the chat using a specific chat invite
/// <para>Possible errors</para>
/// Code Type Description
/// 400 CHANNEL_INVALID The provided channel is invalid.
/// 400 CHANNEL_PRIVATE You haven't joined this channel/supergroup.
/// 400 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 INVITE_HASH_EXPIRED The invite link has expired.
/// 400 PEER_ID_INVALID The provided peer id is invalid.
/// 400 SEARCH_WITH_LINK_NOT_SUPPORTED You cannot provide a search query and an invite link at the same time.
/// See <a href="https://corefork.telegram.org/method/messages.getChatInviteImporters" />
///</summary>
[TlObject(0xdf04dd4e)]
public sealed class RequestGetChatInviteImporters : IRequest<MyTelegram.Schema.Messages.IChatInviteImporters>
{
    public uint ConstructorId => 0xdf04dd4e;
    ///<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>
    /// If set, only returns info about users with pending <a href="https://corefork.telegram.org/api/invites#join-requests">join requests »</a>
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Requested { get; set; }

    ///<summary>
    /// Set this flag if the link is a <a href="https://corefork.telegram.org/api/stars#star-subscriptions">Telegram Star subscription link »</a> and only members with already expired subscription must be returned.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool SubscriptionExpired { get; set; }

    ///<summary>
    /// Chat
    /// See <a href="https://corefork.telegram.org/type/InputPeer" />
    ///</summary>
    public MyTelegram.Schema.IInputPeer Peer { get; set; }

    ///<summary>
    /// Invite link
    ///</summary>
    public string? Link { get; set; }

    ///<summary>
    /// Search for a user in the pending <a href="https://corefork.telegram.org/api/invites#join-requests">join requests »</a> list: only available when the <code>requested</code> flag is set, cannot be used together with a specific <code>link</code>.
    ///</summary>
    public string? Q { get; set; }

    ///<summary>
    /// <a href="https://corefork.telegram.org/api/offsets">Offsets for pagination, for more info click here</a>
    ///</summary>
    public int OffsetDate { get; set; }

    ///<summary>
    /// User ID for <a href="https://corefork.telegram.org/api/offsets">pagination</a>: if set, <code>offset_date</code> must also be set.
    /// See <a href="https://corefork.telegram.org/type/InputUser" />
    ///</summary>
    public MyTelegram.Schema.IInputUser OffsetUser { 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 (Requested) { Flags = Flags.SetBit(0); }
        if (SubscriptionExpired) { Flags = Flags.SetBit(3); }
        if (Link != null) { Flags = Flags.SetBit(1); }
        if (Q != null) { Flags = Flags.SetBit(2); }

    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(Peer);
        if (Flags.IsBitSet(1)) { writer.Write(Link); }
        if (Flags.IsBitSet(2)) { writer.Write(Q); }
        writer.Write(OffsetDate);
        writer.Write(OffsetUser);
        writer.Write(Limit);
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { Requested = true; }
        if (Flags.IsBitSet(3)) { SubscriptionExpired = true; }
        Peer = buffer.Read<MyTelegram.Schema.IInputPeer>();
        if (Flags.IsBitSet(1)) { Link = buffer.ReadString(); }
        if (Flags.IsBitSet(2)) { Q = buffer.ReadString(); }
        OffsetDate = buffer.ReadInt32();
        OffsetUser = buffer.Read<MyTelegram.Schema.IInputUser>();
        Limit = buffer.ReadInt32();
    }
}
