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

namespace MyTelegram.Schema;

///<summary>
/// We blocked a peer, see <a href="https://corefork.telegram.org/api/block">here »</a> for more info on blocklists.
/// See <a href="https://corefork.telegram.org/constructor/updatePeerBlocked" />
///</summary>
[TlObject(0xebe07752)]
public sealed class TUpdatePeerBlocked : IUpdate
{
    public uint ConstructorId => 0xebe07752;
    ///<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 the peer was blocked or unblocked
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Blocked { get; set; }

    ///<summary>
    /// Whether the peer was added/removed to/from the story blocklist; if not set, this update affects the main blocklist, see <a href="https://corefork.telegram.org/api/block">here »</a> for more info.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool BlockedMyStoriesFrom { get; set; }

    ///<summary>
    /// The (un)blocked peer
    /// See <a href="https://corefork.telegram.org/type/Peer" />
    ///</summary>
    public MyTelegram.Schema.IPeer PeerId { get; set; }

    public void ComputeFlag()
    {
        if (Blocked) { Flags = Flags.SetBit(0); }
        if (BlockedMyStoriesFrom) { Flags = Flags.SetBit(1); }

    }

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

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { Blocked = true; }
        if (Flags.IsBitSet(1)) { BlockedMyStoriesFrom = true; }
        PeerId = buffer.Read<MyTelegram.Schema.IPeer>();
    }
}