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

namespace MyTelegram.Schema.Messages;

///<summary>
/// Pin a message
/// <para>Possible errors</para>
/// Code Type Description
/// 400 BOT_ONESIDE_NOT_AVAIL Bots can't pin messages in PM just for themselves.
/// 400 CHANNEL_PRIVATE You haven't joined this channel/supergroup.
/// 400 CHAT_ADMIN_REQUIRED You must be an admin in this chat to do this.
/// 400 CHAT_NOT_MODIFIED No changes were made to chat information because the new information you passed is identical to the current information.
/// 403 CHAT_WRITE_FORBIDDEN You can't write in this chat.
/// 400 MESSAGE_ID_INVALID The provided message id is invalid.
/// 400 PEER_ID_INVALID The provided peer id is invalid.
/// 400 PIN_RESTRICTED You can't pin messages.
/// 400 USER_BANNED_IN_CHANNEL You're banned from sending messages in supergroups/channels.
/// See <a href="https://corefork.telegram.org/method/messages.updatePinnedMessage" />
///</summary>
[TlObject(0xd2aaf7ec)]
public sealed class RequestUpdatePinnedMessage : IRequest<MyTelegram.Schema.IUpdates>
{
    public uint ConstructorId => 0xd2aaf7ec;
    ///<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>
    /// Pin the message silently, without triggering a notification
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Silent { get; set; }

    ///<summary>
    /// Whether the message should unpinned or pinned
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Unpin { get; set; }

    ///<summary>
    /// Whether the message should only be pinned on the local side of a one-to-one chat
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool PmOneside { get; set; }

    ///<summary>
    /// The peer where to pin the message
    /// See <a href="https://corefork.telegram.org/type/InputPeer" />
    ///</summary>
    public MyTelegram.Schema.IInputPeer Peer { get; set; }

    ///<summary>
    /// The message to pin or unpin
    ///</summary>
    public int Id { get; set; }

    public void ComputeFlag()
    {
        if (Silent) { Flags = Flags.SetBit(0); }
        if (Unpin) { Flags = Flags.SetBit(1); }
        if (PmOneside) { Flags = Flags.SetBit(2); }

    }

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

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { Silent = true; }
        if (Flags.IsBitSet(1)) { Unpin = true; }
        if (Flags.IsBitSet(2)) { PmOneside = true; }
        Peer = buffer.Read<MyTelegram.Schema.IInputPeer>();
        Id = buffer.ReadInt32();
    }
}
