/*
 * SPDX-FileCopyrightText: 2025 Copyright contributors to the cppTango project
 *
 * SPDX-License-Identifier: LGPL-3.0-or-later
 */
#ifndef TANGO_CLIENT_DBSERVER_H
#define TANGO_CLIENT_DBSERVER_H

#include <tango/client/DbDevExportInfo.h>
#include <tango/client/DbDevInfo.h>
#include <tango/client/DbServerInfo.h>

#include <memory>
#include <string>

/** @defgroup DBase Database Client classes
 * @ingroup Client
 */

namespace Tango
{
class Database;

/**********************************************************************
 *                                                                    *
 *  DbServer - A database object for accessing server related         *
 *               information in the database                          *
 *                                                                    *
 **********************************************************************/

/**
 * A database object for a device server which can be used to query or modify server database information.
 *
 * @headerfile tango.h
 * @ingroup DBase
 */
class DbServer
{
  private:
    std::string name;
    Database *dbase;
    int db_ind;
    bool ext_dbase;

    class DbServerExt
    {
      public:
        DbServerExt() { }
    };

    std::unique_ptr<DbServerExt> ext;

  public:
    /**@name Constructors */
    //@{
    /**
     * Create a DbServer instance.
     *
     * A constructor for a DbServer object for a server in the TANGO database specified by the TANGO_HOST
     * environment variable.
     *
     * @param [in] server_name    The device server name
     *
     */
    DbServer(std::string server_name);
    /**
     * Create a DbServer instance using a specified database
     *
     * A constructor for a DbServer object for the server in the specified database. This method reuses the
     * Database supplied by the programmer
     *
     * @param [in] server_name    The device server name
     * @param [in] db The database object
     *
     */
    DbServer(std::string server_name, Database *db);
    //@}
    //
    // methods
    //
    /**@name Server oriented methods */
    //@{
    /**
     * Add a device server process into the database
     *
     * Add a group of devices to the database. The device names, server names and classes are specified in the
     * vector of DbDevInfo structures
     *
     * @param [in] serv Device server process data
     *
     * @exception ConnectionFailed, CommunnicationFailed, DevFailed from device
     */
    void add_server(DbDevInfos &serv);
    /**
     * Delete the device server from database
     *
     * Delete the device server and its associated devices from the database.
     *
     * @exception ConnectionFailed, CommunnicationFailed, DevFailed from device
     */
    void delete_server();
    /**
     * Export all device server devices in database
     *
     * Export a group of device to the database. The device names, IOR, class, server name, pid etc. are specified
     * in the vector of DbDevExportInfo structures.
     *
     * @param [in] serv Devices information
     *
     * @exception ConnectionFailed, CommunnicationFailed, DevFailed from device
     */
    void export_server(DbDevExportInfos &serv);
    /**
     * Mark all devices belonging to the device server as un-exported
     *
     * Mark all the devices exported by the server as un-exported.
     *
     * @exception ConnectionFailed, CommunnicationFailed, DevFailed from device
     */
    void unexport_server();
    //@}

    /// @privatesection
    ~DbServer();

    DbServerInfo get_server_info();
};
} // namespace Tango

#endif // TANGO_CLIENT_DBSERVER_H
