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

namespace MyTelegram.Schema;

///<summary>
/// The Time-To-Live of messages in this chat was changed.
/// See <a href="https://corefork.telegram.org/constructor/messageActionSetMessagesTTL" />
///</summary>
[TlObject(0x3c134d7b)]
public sealed class TMessageActionSetMessagesTTL : IMessageAction
{
    public uint ConstructorId => 0x3c134d7b;
    ///<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>
    /// New Time-To-Live of all messages sent in this chat; if 0, autodeletion was disabled.
    ///</summary>
    public int Period { get; set; }

    ///<summary>
    /// If set, the chat TTL setting was set not due to a manual change by one of participants, but automatically because one of the participants has the <a href="https://corefork.telegram.org/method/messages.setDefaultHistoryTTL">default TTL settings enabled »</a>. For example, when a user writes to us for the first time and we have set a default messages TTL of 1 week, this service message (with <code>auto_setting_from=our_userid</code>) will be emitted before our first message.
    ///</summary>
    public long? AutoSettingFrom { get; set; }

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

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

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