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

namespace MyTelegram.Schema;

///<summary>
/// An <a href="https://corefork.telegram.org/api/emoji-status">emoji status</a>
/// See <a href="https://corefork.telegram.org/constructor/emojiStatus" />
///</summary>
[TlObject(0xe7ff068a)]
public sealed class TEmojiStatus : IEmojiStatus
{
    public uint ConstructorId => 0xe7ff068a;
    public int Flags { get; set; }

    ///<summary>
    /// <a href="https://corefork.telegram.org/api/custom-emoji">Custom emoji document ID</a>
    ///</summary>
    public long DocumentId { get; set; }
    public int? Until { get; set; }

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

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

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