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

namespace MyTelegram.Schema;

///<summary>
/// A certain peer has reposted the story.
/// See <a href="https://corefork.telegram.org/constructor/storyViewPublicRepost" />
///</summary>
[TlObject(0xbd74cf49)]
public sealed class TStoryViewPublicRepost : IStoryView
{
    public uint ConstructorId => 0xbd74cf49;
    ///<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 we have <a href="https://corefork.telegram.org/api/block">completely blocked</a> this user, including from viewing more of our stories.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Blocked { get; set; }

    ///<summary>
    /// Whether we have <a href="https://corefork.telegram.org/api/block">blocked</a> this user from viewing more of our stories.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool BlockedMyStoriesFrom { get; set; }

    ///<summary>
    /// The peer that reposted the story.
    /// See <a href="https://corefork.telegram.org/type/Peer" />
    ///</summary>
    public MyTelegram.Schema.IPeer PeerId { get; set; }

    ///<summary>
    /// The reposted story.
    /// See <a href="https://corefork.telegram.org/type/StoryItem" />
    ///</summary>
    public MyTelegram.Schema.IStoryItem Story { 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);
        writer.Write(Story);
    }

    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>();
        Story = buffer.Read<MyTelegram.Schema.IStoryItem>();
    }
}