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

namespace MyTelegram.Schema;

///<summary>
/// Preview of webpage
/// See <a href="https://corefork.telegram.org/constructor/messageMediaWebPage" />
///</summary>
[TlObject(0xddf10c3b)]
public sealed class TMessageMediaWebPage : IMessageMedia
{
    public uint ConstructorId => 0xddf10c3b;
    ///<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>
    /// If set, specifies that a large media preview should be used.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool ForceLargeMedia { get; set; }

    ///<summary>
    /// If set, specifies that a small media preview should be used.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool ForceSmallMedia { get; set; }

    ///<summary>
    /// If set, indicates that the URL used for the webpage preview was specified manually using <a href="https://corefork.telegram.org/constructor/inputMediaWebPage">inputMediaWebPage</a>, and may not be related to any of the URLs specified in the message.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Manual { get; set; }

    ///<summary>
    /// If set, the webpage can be opened directly without user confirmation; otherwise, user confirmation is required, showing the exact URL that will be opened.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Safe { get; set; }

    ///<summary>
    /// Webpage preview
    /// See <a href="https://corefork.telegram.org/type/WebPage" />
    ///</summary>
    public MyTelegram.Schema.IWebPage Webpage { get; set; }

    public void ComputeFlag()
    {
        if (ForceLargeMedia) { Flags = Flags.SetBit(0); }
        if (ForceSmallMedia) { Flags = Flags.SetBit(1); }
        if (Manual) { Flags = Flags.SetBit(3); }
        if (Safe) { Flags = Flags.SetBit(4); }

    }

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

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { ForceLargeMedia = true; }
        if (Flags.IsBitSet(1)) { ForceSmallMedia = true; }
        if (Flags.IsBitSet(3)) { Manual = true; }
        if (Flags.IsBitSet(4)) { Safe = true; }
        Webpage = buffer.Read<MyTelegram.Schema.IWebPage>();
    }
}