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

namespace MyTelegram.Schema;

///<summary>
/// A folder imported using a <a href="https://corefork.telegram.org/api/links#chat-folder-links">chat folder deep link »</a>.
/// See <a href="https://corefork.telegram.org/constructor/dialogFilterChatlist" />
///</summary>
[TlObject(0x96537bd7)]
public sealed class TDialogFilterChatlist : IDialogFilter
{
    public uint ConstructorId => 0x96537bd7;
    ///<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 the current user has created some <a href="https://corefork.telegram.org/api/links#chat-folder-links">chat folder deep links »</a> to share the folder as well.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool HasMyInvites { get; set; }
    public bool TitleNoanimate { get; set; }

    ///<summary>
    /// ID of the folder
    ///</summary>
    public int Id { get; set; }

    ///<summary>
    /// Name of the folder (max 12 UTF-8 chars)
    /// See <a href="https://corefork.telegram.org/type/TextWithEntities" />
    ///</summary>
    public MyTelegram.Schema.ITextWithEntities Title { get; set; }

    ///<summary>
    /// Emoji to use as icon for the folder.
    ///</summary>
    public string? Emoticon { get; set; }

    ///<summary>
    /// A color ID for the <a href="https://corefork.telegram.org/api/folders#folder-tags">folder tag associated to this folder, see here »</a> for more info.
    ///</summary>
    public int? Color { get; set; }

    ///<summary>
    /// Pinned chats, <a href="https://corefork.telegram.org/api/folders">folders</a> can have unlimited pinned chats
    ///</summary>
    public TVector<MyTelegram.Schema.IInputPeer> PinnedPeers { get; set; }

    ///<summary>
    /// Chats to include in the folder
    ///</summary>
    public TVector<MyTelegram.Schema.IInputPeer> IncludePeers { get; set; }

    public void ComputeFlag()
    {
        if (HasMyInvites) { Flags = Flags.SetBit(26); }
        if (TitleNoanimate) { Flags = Flags.SetBit(28); }
        if (Emoticon != null) { Flags = Flags.SetBit(25); }
        if (/*Color != 0 && */Color.HasValue) { Flags = Flags.SetBit(27); }

    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(Id);
        writer.Write(Title);
        if (Flags.IsBitSet(25)) { writer.Write(Emoticon); }
        if (Flags.IsBitSet(27)) { writer.Write(Color.Value); }
        writer.Write(PinnedPeers);
        writer.Write(IncludePeers);
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(26)) { HasMyInvites = true; }
        if (Flags.IsBitSet(28)) { TitleNoanimate = true; }
        Id = buffer.ReadInt32();
        Title = buffer.Read<MyTelegram.Schema.ITextWithEntities>();
        if (Flags.IsBitSet(25)) { Emoticon = buffer.ReadString(); }
        if (Flags.IsBitSet(27)) { Color = buffer.ReadInt32(); }
        PinnedPeers = buffer.Read<TVector<MyTelegram.Schema.IInputPeer>>();
        IncludePeers = buffer.Read<TVector<MyTelegram.Schema.IInputPeer>>();
    }
}