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

namespace MyTelegram.Schema.Auth;

///<summary>
/// The user should add and verify an email address in order to login as described <a href="https://corefork.telegram.org/api/auth#email-verification">here »</a>.
/// See <a href="https://corefork.telegram.org/constructor/auth.sentCodeTypeSetUpEmailRequired" />
///</summary>
[TlObject(0xa5491dea)]
public sealed class TSentCodeTypeSetUpEmailRequired : ISentCodeType
{
    public uint ConstructorId => 0xa5491dea;
    ///<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 authorization through Apple ID is allowed
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool AppleSigninAllowed { get; set; }

    ///<summary>
    /// Whether authorization through Google ID is allowed
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool GoogleSigninAllowed { get; set; }

    public void ComputeFlag()
    {
        if (AppleSigninAllowed) { Flags = Flags.SetBit(0); }
        if (GoogleSigninAllowed) { Flags = Flags.SetBit(1); }
    }

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

    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { AppleSigninAllowed = true; }
        if (Flags.IsBitSet(1)) { GoogleSigninAllowed = true; }
    }
}