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

namespace MyTelegram.Schema;

///<summary>
/// Discarded or deleted chat.
/// See <a href="https://corefork.telegram.org/constructor/encryptedChatDiscarded" />
///</summary>
[TlObject(0x1e1c7c45)]
public sealed class TEncryptedChatDiscarded : IEncryptedChat
{
    public uint ConstructorId => 0x1e1c7c45;
    ///<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>
    /// Whether both users of this secret chat should also remove all of its messages
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool HistoryDeleted { get; set; }

    ///<summary>
    /// Chat ID
    ///</summary>
    public int Id { get; set; }

    public void ComputeFlag()
    {
        if (HistoryDeleted) { Flags = Flags.SetBit(0); }

    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(Id);
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { HistoryDeleted = true; }
        Id = buffer.ReadInt32();
    }
}