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

namespace MyTelegram.Schema.Smsjobs;

///<summary>
/// Finish an SMS job (official clients only).
/// <para>Possible errors</para>
/// Code Type Description
/// 400 SMSJOB_ID_INVALID The specified job ID is invalid.
/// See <a href="https://corefork.telegram.org/method/smsjobs.finishJob" />
///</summary>
[TlObject(0x4f1ebf24)]
public sealed class RequestFinishJob : IRequest<IBool>
{
    public uint ConstructorId => 0x4f1ebf24;
    ///<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>
    /// Job ID.
    ///</summary>
    public string JobId { get; set; }

    ///<summary>
    /// If failed, the error.
    ///</summary>
    public string? Error { get; set; }

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

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

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