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

namespace MyTelegram.Schema;

///<summary>
/// Video
/// See <a href="https://corefork.telegram.org/constructor/pageBlockVideo" />
///</summary>
[TlObject(0x7c8fe7b6)]
public sealed class TPageBlockVideo : IPageBlock
{
    public uint ConstructorId => 0x7c8fe7b6;
    ///<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 video is set to autoplay
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Autoplay { get; set; }

    ///<summary>
    /// Whether the video is set to loop
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Loop { get; set; }

    ///<summary>
    /// Video ID
    ///</summary>
    public long VideoId { get; set; }

    ///<summary>
    /// Caption
    /// See <a href="https://corefork.telegram.org/type/PageCaption" />
    ///</summary>
    public MyTelegram.Schema.IPageCaption Caption { get; set; }

    public void ComputeFlag()
    {
        if (Autoplay) { Flags = Flags.SetBit(0); }
        if (Loop) { Flags = Flags.SetBit(1); }

    }

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

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { Autoplay = true; }
        if (Flags.IsBitSet(1)) { Loop = true; }
        VideoId = buffer.ReadInt64();
        Caption = buffer.Read<MyTelegram.Schema.IPageCaption>();
    }
}