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

namespace MyTelegram.Schema;

///<summary>
/// Info about why a specific user could not be <a href="https://corefork.telegram.org/api/invites#direct-invites">invited »</a>.
/// See <a href="https://corefork.telegram.org/constructor/missingInvitee" />
///</summary>
[TlObject(0x628c9224)]
public sealed class TMissingInvitee : IMissingInvitee
{
    public uint ConstructorId => 0x628c9224;
    ///<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, we could not add the user <em>only because</em> the current account needs to purchase a <a href="https://corefork.telegram.org/api/premium">Telegram Premium</a> subscription to complete the operation.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool PremiumWouldAllowInvite { get; set; }

    ///<summary>
    /// If set, we could not add the user because of their privacy settings, and additionally, the current account needs to purchase a <a href="https://corefork.telegram.org/api/premium">Telegram Premium</a> subscription to directly share an invite link with the user via a private message.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool PremiumRequiredForPm { get; set; }

    ///<summary>
    /// ID of the user. If neither of the flags below are set, we could not add the user because of their privacy settings, and we can create and directly share an <a href="https://corefork.telegram.org/api/invites#invite-links">invite link</a> with them using a normal message, instead.
    ///</summary>
    public long UserId { get; set; }

    public void ComputeFlag()
    {
        if (PremiumWouldAllowInvite) { Flags = Flags.SetBit(0); }
        if (PremiumRequiredForPm) { Flags = Flags.SetBit(1); }

    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(UserId);
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { PremiumWouldAllowInvite = true; }
        if (Flags.IsBitSet(1)) { PremiumRequiredForPm = true; }
        UserId = buffer.ReadInt64();
    }
}