/*
 * Copyright (c) 2016, 2025, Oracle and/or its affiliates.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License, version 2.0,
 * as published by the Free Software Foundation.
 *
 * This program is designed to work with certain software (including
 * but not limited to OpenSSL) that is licensed under separate terms,
 * as designated in a particular file or component or in included license
 * documentation.  The authors of MySQL hereby grant you an additional
 * permission to link the program and your derivative works with the
 * separately licensed software that they have either included with
 * the program or referenced in the documentation.
 *
 * This program is distributed in the hope that it will be useful,  but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
 * the GNU General Public License, version 2.0, for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 */

#ifndef _MOD_MYSQL_H_
#define _MOD_MYSQL_H_

#include <string>

#include "mysqlshdk/include/scripting/module_registry.h"

namespace mysqlshdk {
namespace db {

class Connection_options;

}  // namespace db
}  // namespace mysqlshdk

namespace mysqlsh {
/**
 * \defgroup mysql mysql
 * \ingroup ShellAPI
 * $(MYSQL_BRIEF)
 *
 * $(MYSQL_DETAIL)
 *
 * $(MYSQL_DETAIL1)
 *
 * $(MYSQL_DETAIL2)
 *
 * $(MYSQL_DETAIL3)
 *
 * \if DOXYGEN_JS
 * \code
 * mysql-js> var mysql = require('mysql');
 *
 * // Then you can use the module functions and properties
 * // for example to create a session
 * mysql-js> var mySession = mysql.getClassicSession('admin@localhost');
 * \endcode
 * \elseif DOXYGEN_PY
 * \code
 * mysql-py> from mysqlsh import mysql
 *
 * // Then you can use the module functions and properties
 * // for example to create a session
 * mysql-py> mySession = mysql.get_classic_session('admin@localhost')
 * \endcode
 * \endif
 *
 * $(MYSQL_DETAIL4)
 */
namespace mysql {

#if DOXYGEN_JS
ClassicSession getClassicSession(ConnectionData connectionData,
                                 String password);
ClassicSession getSession(ConnectionData connectionData, String password);
Array splitScript(String script);
Dictionary parseStatementAst(String statements);
Array tokenizeStatement(String statement);
String quoteIdentifier(String s);
String unquoteIdentifier(String s);
String makeAccount(String user, String host);
Dictionary splitAccount(String account);
#elif DOXYGEN_PY
ClassicSession get_classic_session(ConnectionData connectionData, str password);
ClassicSession get_session(ConnectionData connectionData, str password);
list split_script(str script);
dict parse_statement_ast(str statements);
list tokenize_statement(str statement);
str quote_identifier(str s);
str unquote_identifier(str s);
str make_account(str user, str host);
dict split_account(str account);
#endif

DECLARE_MODULE(Mysql, mysql);

// We need to hide these from doxygen to avoid warnings
#if !defined DOXYGEN_JS && !defined DOXYGEN_PY
std::shared_ptr<shcore::Object_bridge> get_session(
    const mysqlshdk::db::Connection_options &co,
    const char *password = nullptr);

virtual shcore::Value get_member(const std::string &prop) const;
#endif

shcore::Value split_script(const std::string &script) const;
shcore::Value parse_statement_ast(const std::string &statement) const;
shcore::Value tokenize_statement(const std::string &statement) const;

std::string quote_identifier(const std::string &s) const;
std::string unquote_identifier(const std::string &s) const;

std::string make_account(const std::string &user, const std::string &host);
shcore::Value split_account(const std::string &s);

private:
shcore::Object_bridge_ref _type;

END_DECLARE_MODULE();
}  // namespace mysql
}  // namespace mysqlsh

#endif
