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

namespace MyTelegram.Schema;

///<summary>
/// Information about the current <a href="https://corefork.telegram.org/api/stories#stealth-mode">stealth mode</a> session.
/// See <a href="https://corefork.telegram.org/constructor/storiesStealthMode" />
///</summary>
[TlObject(0x712e27fd)]
public sealed class TStoriesStealthMode : IStoriesStealthMode
{
    public uint ConstructorId => 0x712e27fd;
    ///<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 date up to which stealth mode will be active.
    ///</summary>
    public int? ActiveUntilDate { get; set; }

    ///<summary>
    /// The date starting from which the user will be allowed to re-enable stealth mode again.
    ///</summary>
    public int? CooldownUntilDate { get; set; }

    public void ComputeFlag()
    {
        if (/*ActiveUntilDate != 0 && */ActiveUntilDate.HasValue) { Flags = Flags.SetBit(0); }
        if (/*CooldownUntilDate != 0 && */CooldownUntilDate.HasValue) { Flags = Flags.SetBit(1); }
    }

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

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