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

namespace MyTelegram.Schema.Auth;

///<summary>
/// Resend the login code via another medium, the phone code type is determined by the return value of the previous auth.sendCode/auth.resendCode: see <a href="https://corefork.telegram.org/api/auth">login</a> for more info.
/// <para>Possible errors</para>
/// Code Type Description
/// 400 PHONE_CODE_EMPTY phone_code is missing.
/// 400 PHONE_CODE_EXPIRED The phone code you provided has expired.
/// 400 PHONE_CODE_HASH_EMPTY phone_code_hash is missing.
/// 406 PHONE_NUMBER_INVALID The phone number is invalid.
/// 406 SEND_CODE_UNAVAILABLE Returned when all available options for this type of number were already used (e.g. flash-call, then SMS, then this error might be returned to trigger a second resend).
/// See <a href="https://corefork.telegram.org/method/auth.resendCode" />
///</summary>
[TlObject(0xcae47523)]
public sealed class RequestResendCode : IRequest<MyTelegram.Schema.Auth.ISentCode>
{
    public uint ConstructorId => 0xcae47523;
    ///<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 phone number
    ///</summary>
    public string PhoneNumber { get; set; }

    ///<summary>
    /// The phone code hash obtained from <a href="https://corefork.telegram.org/method/auth.sendCode">auth.sendCode</a>
    ///</summary>
    public string PhoneCodeHash { get; set; }

    ///<summary>
    /// Official clients only, used if the device integrity verification failed, and no secret could be obtained to invoke <a href="https://corefork.telegram.org/method/auth.requestFirebaseSms">auth.requestFirebaseSms</a>: in this case, the device integrity verification failure reason must be passed here.
    ///</summary>
    public string? Reason { get; set; }

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

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

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