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

namespace MyTelegram.Schema.Auth;

///<summary>
/// The code was sent via SMS as a secret word, starting with the letter specified in <code>beginning</code>
/// See <a href="https://corefork.telegram.org/constructor/auth.sentCodeTypeSmsWord" />
///</summary>
[TlObject(0xa416ac81)]
public sealed class TSentCodeTypeSmsWord : ISentCodeType
{
    public uint ConstructorId => 0xa416ac81;
    ///<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, the secret word in the sent SMS (which may contain multiple words) starts with this letter.
    ///</summary>
    public string? Beginning { get; set; }

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

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

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { Beginning = buffer.ReadString(); }
    }
}