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

namespace MyTelegram.Schema.Chatlists;

///<summary>
/// Edit a <a href="https://corefork.telegram.org/api/links#chat-folder-links">chat folder deep link »</a>.
/// <para>Possible errors</para>
/// Code Type Description
/// 400 CHANNEL_INVALID The provided channel is invalid.
/// 400 FILTER_ID_INVALID The specified filter ID is invalid.
/// 400 FILTER_NOT_SUPPORTED The specified filter cannot be used in this context.
/// 400 INVITE_SLUG_EMPTY The specified invite slug is empty.
/// 400 INVITE_SLUG_EXPIRED The specified chat folder link has expired.
/// 400 PEERS_LIST_EMPTY The specified list of peers is empty.
/// See <a href="https://corefork.telegram.org/method/chatlists.editExportedInvite" />
///</summary>
[TlObject(0x653db63d)]
public sealed class RequestEditExportedInvite : IRequest<MyTelegram.Schema.IExportedChatlistInvite>
{
    public uint ConstructorId => 0x653db63d;
    ///<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>
    /// Folder ID
    /// See <a href="https://corefork.telegram.org/type/InputChatlist" />
    ///</summary>
    public MyTelegram.Schema.IInputChatlist Chatlist { get; set; }

    ///<summary>
    /// <code>slug</code> obtained from the <a href="https://corefork.telegram.org/api/links#chat-folder-links">chat folder deep link »</a>.
    ///</summary>
    public string Slug { get; set; }

    ///<summary>
    /// If set, sets a new name for the link
    ///</summary>
    public string? Title { get; set; }

    ///<summary>
    /// If set, changes the list of peers shared with the link
    ///</summary>
    public TVector<MyTelegram.Schema.IInputPeer>? Peers { get; set; }

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

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(Chatlist);
        writer.Write(Slug);
        if (Flags.IsBitSet(1)) { writer.Write(Title); }
        if (Flags.IsBitSet(2)) { writer.Write(Peers); }
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        Chatlist = buffer.Read<MyTelegram.Schema.IInputChatlist>();
        Slug = buffer.ReadString();
        if (Flags.IsBitSet(1)) { Title = buffer.ReadString(); }
        if (Flags.IsBitSet(2)) { Peers = buffer.Read<TVector<MyTelegram.Schema.IInputPeer>>(); }
    }
}
