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

namespace MyTelegram.Schema.Messages;

///<summary>
/// Cancels a request for creation and/or delete info on secret chat.
/// <para>Possible errors</para>
/// Code Type Description
/// 400 CHAT_ID_EMPTY The provided chat ID is empty.
/// 400 ENCRYPTION_ALREADY_ACCEPTED Secret chat already accepted.
/// 400 ENCRYPTION_ALREADY_DECLINED The secret chat was already declined.
/// 400 ENCRYPTION_ID_INVALID The provided secret chat ID is invalid.
/// See <a href="https://corefork.telegram.org/method/messages.discardEncryption" />
///</summary>
[TlObject(0xf393aea0)]
public sealed class RequestDiscardEncryption : IRequest<IBool>
{
    public uint ConstructorId => 0xf393aea0;
    ///<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 the entire chat history for the other user as well
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool DeleteHistory { get; set; }

    ///<summary>
    /// Secret chat ID
    ///</summary>
    public int ChatId { get; set; }

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

    }

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

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