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

namespace MyTelegram.Schema;

///<summary>
/// Required type
/// See <a href="https://corefork.telegram.org/constructor/secureRequiredType" />
///</summary>
[TlObject(0x829d99da)]
public sealed class TSecureRequiredType : ISecureRequiredType
{
    public uint ConstructorId => 0x829d99da;
    ///<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>
    /// Native names
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool NativeNames { get; set; }

    ///<summary>
    /// Is a selfie required
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool SelfieRequired { get; set; }

    ///<summary>
    /// Is a translation required
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool TranslationRequired { get; set; }

    ///<summary>
    /// Secure value type
    /// See <a href="https://corefork.telegram.org/type/SecureValueType" />
    ///</summary>
    public MyTelegram.Schema.ISecureValueType Type { get; set; }

    public void ComputeFlag()
    {
        if (NativeNames) { Flags = Flags.SetBit(0); }
        if (SelfieRequired) { Flags = Flags.SetBit(1); }
        if (TranslationRequired) { Flags = Flags.SetBit(2); }

    }

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

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { NativeNames = true; }
        if (Flags.IsBitSet(1)) { SelfieRequired = true; }
        if (Flags.IsBitSet(2)) { TranslationRequired = true; }
        Type = buffer.Read<MyTelegram.Schema.ISecureValueType>();
    }
}