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

namespace MyTelegram.Schema;

///<summary>
/// Specifies the chats that <strong>can</strong> receive Telegram Business <a href="https://corefork.telegram.org/api/business#away-messages">away »</a> and <a href="https://corefork.telegram.org/api/business#greeting-messages">greeting »</a> messages.If <code>exclude_selected</code> is set, specifies all chats that <strong>cannot</strong> receive Telegram Business <a href="https://corefork.telegram.org/api/business#away-messages">away »</a> and <a href="https://corefork.telegram.org/api/business#greeting-messages">greeting »</a> messages.
/// See <a href="https://corefork.telegram.org/constructor/inputBusinessRecipients" />
///</summary>
[TlObject(0x6f8b32aa)]
public sealed class TInputBusinessRecipients : IInputBusinessRecipients
{
    public uint ConstructorId => 0x6f8b32aa;
    ///<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>
    /// All existing private chats.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool ExistingChats { get; set; }

    ///<summary>
    /// All new private chats.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool NewChats { get; set; }

    ///<summary>
    /// All private chats with contacts.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Contacts { get; set; }

    ///<summary>
    /// All private chats with non-contacts.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool NonContacts { get; set; }

    ///<summary>
    /// If set, inverts the selection.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool ExcludeSelected { get; set; }

    ///<summary>
    /// Only private chats with the specified users.
    ///</summary>
    public TVector<MyTelegram.Schema.IInputUser>? Users { get; set; }

    public void ComputeFlag()
    {
        if (ExistingChats) { Flags = Flags.SetBit(0); }
        if (NewChats) { Flags = Flags.SetBit(1); }
        if (Contacts) { Flags = Flags.SetBit(2); }
        if (NonContacts) { Flags = Flags.SetBit(3); }
        if (ExcludeSelected) { Flags = Flags.SetBit(5); }
        if (Users?.Count > 0) { Flags = Flags.SetBit(4); }
    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        if (Flags.IsBitSet(4)) { writer.Write(Users); }
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { ExistingChats = true; }
        if (Flags.IsBitSet(1)) { NewChats = true; }
        if (Flags.IsBitSet(2)) { Contacts = true; }
        if (Flags.IsBitSet(3)) { NonContacts = true; }
        if (Flags.IsBitSet(5)) { ExcludeSelected = true; }
        if (Flags.IsBitSet(4)) { Users = buffer.Read<TVector<MyTelegram.Schema.IInputUser>>(); }
    }
}