/*
 * SPDX-FileCopyrightText: Copyright 2023-2024 Open Mobile Platform LLC <community@omp.ru>
 * SPDX-License-Identifier: Proprietary
 */

#pragma once

#include "ieglcontextdelegate.h"

#include <vector>
#include <QMap>
#include <QString>

namespace Aurora {
namespace WebView {
namespace WebEngineContext {

/**
    Initialize browser brocesses context.

    Web engine creates auxiliary processes during work via forking the original
    process several times. You must call that function as early as
    possible to proper initialize the context and to not mix it with an application logic.

    This function returns only for initial process.

    You can use use additional command line arguments, or pass them from your code using the
    additionalArgs parameter. The supported arguments are listed in the table below.

     Condition                        | Explanation
    ----------------------------------|-------------------------------------------------------
     ignore-certificate-errors        | A set of public key hashes for which to ignore
                                      | certificate-related errors. If the certificate
                                      | chain presented by the server does not validate,
                                      | and one or more certificates have public key
                                      | hashes that match a key from this list, the error
                                      | is ignored. The switch value must be a 5241
                                      | comma-separated list of Base64-encoded SHA-256 SPKI
                                      | Fingerprints (RFC 7469, Section 2.4).
    ----------------------------------|-------------------------------------------------------
     disable-web-security             | Don't enforce the same-origin policy; meant for
                                      | website testing only. It disables CORS checks, ORB
                                      | mechanism and PNA checks.
    ----------------------------------|-------------------------------------------------------
     remote-debugging-port            | Enables remote debug over HTTP on the specified port
    ----------------------------------|-------------------------------------------------------
     remote-allow-origins             | Enables web socket connections from the specified
                                      | origins only. '*' allows any origin.
    ----------------------------------|-------------------------------------------------------
     disable-accelerated-video-encode | Disables hardware acceleration of video encode, where
                                      | available.
    ----------------------------------|-------------------------------------------------------
     default-encoding                 | Sets the encoding used by default. The default value
                                      | is "ISO-8859-1".

    @deprecated Use InitBrowser(int argc, ...) instead
    @param argc number of command line arguments
    @param argv command line arguments
    @param additionalArgs additional arguments to forward to the engine. Optional argument
    @param eglDelegate EGL context platform provider for GPU composition. May be nullptr for QGuiApplication-based applications
*/
[[deprecated("Use InitBrowser(int argc, ...) instead")]]
void StartProcess(
    int argc,
    char *argv[],
    const std::vector<std::string> &additionalArgs = {},
    IEglContextDelegatePtr eglDelegate = nullptr);

/**
    Initialize browser engine to do actual work.

    You can use use additional command line arguments, or pass them from your code using the
    additionalArgs parameter. The supported arguments are listed in the table below.

     Condition                        | Explanation
    ----------------------------------|-------------------------------------------------------
     ignore-certificate-errors        | A set of public key hashes for which to ignore
                                      | certificate-related errors. If the certificate
                                      | chain presented by the server does not validate,
                                      | and one or more certificates have public key
                                      | hashes that match a key from this list, the error
                                      | is ignored. The switch value must be a 5241
                                      | comma-separated list of Base64-encoded SHA-256 SPKI
                                      | Fingerprints (RFC 7469, Section 2.4).
    ----------------------------------|-------------------------------------------------------
     disable-web-security             | Don't enforce the same-origin policy; meant for
                                      | website testing only. It disables CORS checks, ORB
                                      | mechanism and PNA checks.
    ----------------------------------|-------------------------------------------------------
     remote-debugging-port            | Enables remote debug over HTTP on the specified port
    ----------------------------------|-------------------------------------------------------
     remote-allow-origins             | Enables web socket connections from the specified
                                      | origins only. '*' allows any origin.
    ----------------------------------|-------------------------------------------------------
     disable-accelerated-video-encode | Disables hardware acceleration of video encode, where
                                      | available.
    ----------------------------------|-------------------------------------------------------
     default-encoding                 | Sets the encoding used by default. The default value
                                      | is "ISO-8859-1".
    ----------------------------------|-------------------------------------------------------
     browser-subprocess-path          | The path to a separate executable that will be
                                      | launched for sub-processes. It can be used in
                                      | additionalArgs param only.

    @param params optional webview params
    @param argc number of command line arguments
    @param argv command line arguments
    @param additionalArgs additional arguments to forward to the engine. Optional argument
    @param eglDelegate EGL context platform provider for GPU composition. May be nullptr for QGuiApplication-based applications
*/
void InitBrowser(
    int argc,
    char *argv[],
    const std::vector<std::string> &additionalArgs = {},
    QMap<QString, QString> params = {},
    IEglContextDelegatePtr eglDelegate = nullptr);

/**
    Initialize browser engine to do actual work.

    @deprecated Use InitBrowser(int argc, ...) instead
    @param params optional webview params
*/
[[deprecated("Use InitBrowser(int argc, ...) instead")]]
void InitBrowser(QMap<QString, QString> params = {});

} // namespace WebEngineContext
} // namespace WebView
} // namespace Aurora
