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

namespace MyTelegram.Schema.Messages;

///<summary>
/// Get info about the chat invites of a specific chat
/// <para>Possible errors</para>
/// Code Type Description
/// 400 ADMIN_ID_INVALID The specified admin ID is invalid.
/// 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 PEER_ID_INVALID The provided peer id is invalid.
/// See <a href="https://corefork.telegram.org/method/messages.getExportedChatInvites" />
///</summary>
[TlObject(0xa2b5a3f6)]
public sealed class RequestGetExportedChatInvites : IRequest<MyTelegram.Schema.Messages.IExportedChatInvites>
{
    public uint ConstructorId => 0xa2b5a3f6;
    ///<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 fetch revoked chat invites
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Revoked { get; set; }

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

    ///<summary>
    /// Whether to only fetch chat invites from this admin
    /// See <a href="https://corefork.telegram.org/type/InputUser" />
    ///</summary>
    public MyTelegram.Schema.IInputUser AdminId { 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>
    /// <a href="https://corefork.telegram.org/api/offsets">Offsets for pagination, for more info click here</a>
    ///</summary>
    public string? OffsetLink { 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 (Revoked) { Flags = Flags.SetBit(3); }
        if (/*OffsetDate != 0 && */OffsetDate.HasValue) { Flags = Flags.SetBit(2); }
        if (OffsetLink != null) { Flags = Flags.SetBit(2); }

    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(Peer);
        writer.Write(AdminId);
        if (Flags.IsBitSet(2)) { writer.Write(OffsetDate.Value); }
        if (Flags.IsBitSet(2)) { writer.Write(OffsetLink); }
        writer.Write(Limit);
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(3)) { Revoked = true; }
        Peer = buffer.Read<MyTelegram.Schema.IInputPeer>();
        AdminId = buffer.Read<MyTelegram.Schema.IInputUser>();
        if (Flags.IsBitSet(2)) { OffsetDate = buffer.ReadInt32(); }
        if (Flags.IsBitSet(2)) { OffsetLink = buffer.ReadString(); }
        Limit = buffer.ReadInt32();
    }
}
