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

namespace MyTelegram.Schema.Account;

///<summary>
/// Private info associated to the password info (recovery email, telegram <a href="https://corefork.telegram.org/passport">passport</a> info &amp; so on)
/// See <a href="https://corefork.telegram.org/constructor/account.passwordSettings" />
///</summary>
[TlObject(0x9a5c33e5)]
public sealed class TPasswordSettings : IPasswordSettings
{
    public uint ConstructorId => 0x9a5c33e5;
    ///<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>
    /// <a href="https://corefork.telegram.org/api/srp#email-verification">2FA Recovery email</a>
    ///</summary>
    public string? Email { get; set; }

    ///<summary>
    /// Telegram <a href="https://corefork.telegram.org/passport">passport</a> settings
    /// See <a href="https://corefork.telegram.org/type/SecureSecretSettings" />
    ///</summary>
    public MyTelegram.Schema.ISecureSecretSettings? SecureSettings { get; set; }

    public void ComputeFlag()
    {
        if (Email != null) { Flags = Flags.SetBit(0); }
        if (SecureSettings != null) { Flags = Flags.SetBit(1); }
    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        if (Flags.IsBitSet(0)) { writer.Write(Email); }
        if (Flags.IsBitSet(1)) { writer.Write(SecureSettings); }
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { Email = buffer.ReadString(); }
        if (Flags.IsBitSet(1)) { SecureSettings = buffer.Read<MyTelegram.Schema.ISecureSecretSettings>(); }
    }
}