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

namespace MyTelegram.Schema.Messages;

///<summary>
/// Deletes messages by their identifiers.
/// <para>Possible errors</para>
/// Code Type Description
/// 403 MESSAGE_DELETE_FORBIDDEN You can't delete one of the messages you tried to delete, most likely because it is a service message.
/// 400 MESSAGE_ID_INVALID The provided message id is invalid.
/// See <a href="https://corefork.telegram.org/method/messages.deleteMessages" />
///</summary>
[TlObject(0xe58e95d2)]
public sealed class RequestDeleteMessages : IRequest<MyTelegram.Schema.Messages.IAffectedMessages>
{
    public uint ConstructorId => 0xe58e95d2;
    ///<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 to delete messages for all participants of the chat
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Revoke { get; set; }

    ///<summary>
    /// Message ID list
    ///</summary>
    public TVector<int> Id { get; set; }

    public void ComputeFlag()
    {
        if (Revoke) { 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)) { Revoke = true; }
        Id = buffer.Read<TVector<int>>();
    }
}
