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

namespace MyTelegram.Schema.Account;

///<summary>
/// Settings for setting up a new password
/// See <a href="https://corefork.telegram.org/constructor/account.passwordInputSettings" />
///</summary>
[TlObject(0xc23727c9)]
public sealed class TPasswordInputSettings : IPasswordInputSettings
{
    public uint ConstructorId => 0xc23727c9;
    ///<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>
    /// The <a href="https://corefork.telegram.org/api/srp">SRP algorithm</a> to use
    /// See <a href="https://corefork.telegram.org/type/PasswordKdfAlgo" />
    ///</summary>
    public MyTelegram.Schema.IPasswordKdfAlgo? NewAlgo { get; set; }

    ///<summary>
    /// The <a href="https://corefork.telegram.org/api/srp">computed password hash</a>
    ///</summary>
    public byte[]? NewPasswordHash { get; set; }

    ///<summary>
    /// Text hint for the password
    ///</summary>
    public string? Hint { get; set; }

    ///<summary>
    /// Password recovery email
    ///</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? NewSecureSettings { get; set; }

    public void ComputeFlag()
    {
        if (NewAlgo != null) { Flags = Flags.SetBit(0); }
        if (NewPasswordHash != null) { Flags = Flags.SetBit(0); }
        if (Hint != null) { Flags = Flags.SetBit(0); }
        if (Email != null) { Flags = Flags.SetBit(1); }
        if (NewSecureSettings != null) { Flags = Flags.SetBit(2); }
    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        if (Flags.IsBitSet(0)) { writer.Write(NewAlgo); }
        if (Flags.IsBitSet(0)) { writer.Write(NewPasswordHash); }
        if (Flags.IsBitSet(0)) { writer.Write(Hint); }
        if (Flags.IsBitSet(1)) { writer.Write(Email); }
        if (Flags.IsBitSet(2)) { writer.Write(NewSecureSettings); }
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { NewAlgo = buffer.Read<MyTelegram.Schema.IPasswordKdfAlgo>(); }
        if (Flags.IsBitSet(0)) { NewPasswordHash = buffer.ReadBytes(); }
        if (Flags.IsBitSet(0)) { Hint = buffer.ReadString(); }
        if (Flags.IsBitSet(1)) { Email = buffer.ReadString(); }
        if (Flags.IsBitSet(2)) { NewSecureSettings = buffer.Read<MyTelegram.Schema.ISecureSecretSettings>(); }
    }
}