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

namespace MyTelegram.Schema.Messages;

///<summary>
/// Manually mark dialog as unread
/// <para>Possible errors</para>
/// Code Type Description
/// 400 PEER_ID_INVALID The provided peer id is invalid.
/// See <a href="https://corefork.telegram.org/method/messages.markDialogUnread" />
///</summary>
[TlObject(0x8c5006f8)]
public sealed class RequestMarkDialogUnread : IRequest<IBool>
{
    public uint ConstructorId => 0x8c5006f8;
    ///<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>
    /// Mark as unread/read
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Unread { get; set; }
    public MyTelegram.Schema.IInputPeer? ParentPeer { get; set; }

    ///<summary>
    /// Dialog
    /// See <a href="https://corefork.telegram.org/type/InputDialogPeer" />
    ///</summary>
    public MyTelegram.Schema.IInputDialogPeer Peer { get; set; }

    public void ComputeFlag()
    {
        if (Unread) { Flags = Flags.SetBit(0); }
        if (ParentPeer != null) { Flags = Flags.SetBit(1); }

    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        if (Flags.IsBitSet(1)) { writer.Write(ParentPeer); }
        writer.Write(Peer);
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { Unread = true; }
        if (Flags.IsBitSet(1)) { ParentPeer = buffer.Read<MyTelegram.Schema.IInputPeer>(); }
        Peer = buffer.Read<MyTelegram.Schema.IInputDialogPeer>();
    }
}
