/*
 * SPDX-FileCopyrightText: 2025 Copyright contributors to the cppTango project
 *
 * SPDX-License-Identifier: LGPL-3.0-or-later
 */
//=============================================================================
// class GroupReply : base class for group reply
//=============================================================================

#ifndef TANGO_CLIENT_GROUPREPLY_H
#define TANGO_CLIENT_GROUPREPLY_H

#include <tango/server/Except.h>

#include <string>

namespace Tango
{
/**
 * Base class for Group reply
 *
 *
 * @headerfile tango.h
 * @ingroup Grp
 */

class GroupReply
{
  public:
    ///@privatesection
    //- default ctor
    GroupReply();

    //- ctor
    GroupReply(const std::string &dev_name, const std::string &obj_name, bool group_element_enabled = true);
    //- ctor
    GroupReply(const std::string &dev_name,
               const std::string &obj_name,
               const DevFailed &exception,
               bool group_element_enabled = true);

    //- dtor
    virtual ~GroupReply();

    GroupReply(const GroupReply &);
    GroupReply &operator=(const GroupReply &);

    GroupReply(GroupReply &&);
    GroupReply &operator=(GroupReply &&);

    ///@publicsection
    /**
     * Check if the group element corresponding to this reply is enabled.
     *
     * @return true if corresponding element is enabled, false otherwise
     */
    bool group_element_enabled() const
    {
        return group_element_enabled_m;
    }

    //- enable/disable exception - returns the previous mode
    /**
     * Enable/Disable exception
     *
     * Set the group exception mode. If set to true, exception will be thrown
     * (when needed) by the library when the user get command  execution result.
     * If set to false (the default), the user has to deal with the has_failed()
     * exception to manage cases of wrong execution command.
     *
     * @param [in] exception_mode The new exception mode
     * @return The previous exception mode
     */
    static bool enable_exception(bool exception_mode = true);

    //- has_failed accessor
    /**
     * Check if an error has occurred
     *
     * Returns a boolean set to true if the command executed on the group
     * element has failed. Otherwise, returns false
     *
     * @return The error flag
     */
    bool has_failed() const
    {
        return has_failed_m;
    }

    //- device name accessor
    /**
     * Get device name
     *
     * Returns the device name for the group element
     *
     * @return The device name
     */
    const std::string &dev_name() const
    {
        return dev_name_m;
    }

    //- object (i.e. command or attribute) name accessor
    /**
     * Get object name
     *
     * Returns the object name (i.e. command or attribute) for the group element
     *
     * @return The object name
     */
    const std::string &obj_name() const
    {
        return obj_name_m;
    }

    //- error stack accessor
    /**
     * Get error stack
     *
     * Returns the error stack for the group element
     *
     * @return The error stack
     */
    const DevErrorList &get_err_stack() const
    {
        return exception_m.errors;
    }

  protected:
    ///@privatesection
    //- exception flag (enable/disable)
    TANGO_IMP static bool exception_enabled;
    //- the device name
    std::string dev_name_m;
    //- command or attribute name
    std::string obj_name_m;
    //- has_failed_m: true is an error occurred, false otherwise
    bool has_failed_m;
    //- group_element_enabled_m : true is the associated group member is enabled, false otherwise
    bool group_element_enabled_m;
    //- exception: valid if has_failed_m set to true
    DevFailed exception_m;
};

} // namespace Tango

#endif /* TANGO_CLIENT_GROUPREPLY_H */
