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

namespace MyTelegram.Schema.Messages;

///<summary>
/// Open a <a href="https://corefork.telegram.org/bots/webapps">bot mini app</a> from a <a href="https://corefork.telegram.org/api/links#direct-mini-app-links">direct Mini App deep link</a>, sending over user information after user confirmation.After calling this method, until the user closes the webview, <a href="https://corefork.telegram.org/method/messages.prolongWebView">messages.prolongWebView</a> must be called every 60 seconds.
/// <para>Possible errors</para>
/// Code Type Description
/// 400 BOT_APP_INVALID The specified bot app is invalid.
/// 400 BOT_APP_SHORTNAME_INVALID The specified bot app short name is invalid.
/// See <a href="https://corefork.telegram.org/method/messages.requestAppWebView" />
///</summary>
[TlObject(0x53618bce)]
public sealed class RequestRequestAppWebView : IRequest<MyTelegram.Schema.IWebViewResult>
{
    public uint ConstructorId => 0x53618bce;
    ///<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>
    /// Set this flag if the bot is asking permission to send messages to the user as specified in the <a href="https://corefork.telegram.org/api/links#direct-mini-app-links">direct Mini App deep link</a> docs, and the user agreed.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool WriteAllowed { get; set; }

    ///<summary>
    /// If set, requests to open the mini app in compact mode (as opposed to fullview mode). Must be set if the <code>mode</code> parameter of the <a href="https://corefork.telegram.org/api/links#direct-mini-app-links">direct Mini App deep link</a> is equal to <code>compact</code>.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Compact { get; set; }

    ///<summary>
    /// &nbsp;
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Fullscreen { get; set; }

    ///<summary>
    /// If the client has clicked on the link in a Telegram chat, pass the chat's peer information; otherwise pass the bot's peer information, instead.
    /// See <a href="https://corefork.telegram.org/type/InputPeer" />
    ///</summary>
    public MyTelegram.Schema.IInputPeer Peer { get; set; }

    ///<summary>
    /// The app obtained by invoking <a href="https://corefork.telegram.org/method/messages.getBotApp">messages.getBotApp</a> as specified in the <a href="https://corefork.telegram.org/api/links#direct-mini-app-links">direct Mini App deep link</a> docs.
    /// See <a href="https://corefork.telegram.org/type/InputBotApp" />
    ///</summary>
    public MyTelegram.Schema.IInputBotApp App { get; set; }

    ///<summary>
    /// If the <code>startapp</code> query string parameter is present in the <a href="https://corefork.telegram.org/api/links#direct-mini-app-links">direct Mini App deep link</a>, pass it to <code>start_param</code>.
    ///</summary>
    public string? StartParam { get; set; }

    ///<summary>
    /// <a href="https://corefork.telegram.org/api/bots/webapps#theme-parameters">Theme parameters »</a>
    /// See <a href="https://corefork.telegram.org/type/DataJSON" />
    ///</summary>
    public MyTelegram.Schema.IDataJSON? ThemeParams { get; set; }

    ///<summary>
    /// Short name of the application; 0-64 English letters, digits, and underscores
    ///</summary>
    public string Platform { get; set; }

    public void ComputeFlag()
    {
        if (WriteAllowed) { Flags = Flags.SetBit(0); }
        if (Compact) { Flags = Flags.SetBit(7); }
        if (Fullscreen) { Flags = Flags.SetBit(8); }
        if (StartParam != null) { Flags = Flags.SetBit(1); }
        if (ThemeParams != null) { Flags = Flags.SetBit(2); }

    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(Peer);
        writer.Write(App);
        if (Flags.IsBitSet(1)) { writer.Write(StartParam); }
        if (Flags.IsBitSet(2)) { writer.Write(ThemeParams); }
        writer.Write(Platform);
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { WriteAllowed = true; }
        if (Flags.IsBitSet(7)) { Compact = true; }
        if (Flags.IsBitSet(8)) { Fullscreen = true; }
        Peer = buffer.Read<MyTelegram.Schema.IInputPeer>();
        App = buffer.Read<MyTelegram.Schema.IInputBotApp>();
        if (Flags.IsBitSet(1)) { StartParam = buffer.ReadString(); }
        if (Flags.IsBitSet(2)) { ThemeParams = buffer.Read<MyTelegram.Schema.IDataJSON>(); }
        Platform = buffer.ReadString();
    }
}
