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

namespace MyTelegram.Schema.Smsjobs;

///<summary>
/// Status
/// See <a href="https://corefork.telegram.org/constructor/smsjobs.status" />
///</summary>
[TlObject(0x2aee9191)]
public sealed class TStatus : IStatus
{
    public uint ConstructorId => 0x2aee9191;
    ///<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>
    /// Allow international numbers
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool AllowInternational { get; set; }

    ///<summary>
    /// Recently sent
    ///</summary>
    public int RecentSent { get; set; }

    ///<summary>
    /// Since
    ///</summary>
    public int RecentSince { get; set; }

    ///<summary>
    /// Remaining
    ///</summary>
    public int RecentRemains { get; set; }

    ///<summary>
    /// Total sent
    ///</summary>
    public int TotalSent { get; set; }

    ///<summary>
    /// Total since
    ///</summary>
    public int TotalSince { get; set; }

    ///<summary>
    /// Last gift deep link
    ///</summary>
    public string? LastGiftSlug { get; set; }

    ///<summary>
    /// Terms of service URL
    ///</summary>
    public string TermsUrl { get; set; }

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

    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(RecentSent);
        writer.Write(RecentSince);
        writer.Write(RecentRemains);
        writer.Write(TotalSent);
        writer.Write(TotalSince);
        if (Flags.IsBitSet(1)) { writer.Write(LastGiftSlug); }
        writer.Write(TermsUrl);
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { AllowInternational = true; }
        RecentSent = buffer.ReadInt32();
        RecentSince = buffer.ReadInt32();
        RecentRemains = buffer.ReadInt32();
        TotalSent = buffer.ReadInt32();
        TotalSince = buffer.ReadInt32();
        if (Flags.IsBitSet(1)) { LastGiftSlug = buffer.ReadString(); }
        TermsUrl = buffer.ReadString();
    }
}