#pragma once

#include <sdbusplus/bus.hpp>
#include <sdbusplus/server.hpp>

namespace openpower
{
namespace phal
{
namespace fwupdate
{

static constexpr auto OBJ_SOFTWARE = "/xyz/openbmc_project/software";

/** @class Watch
 *  @brief Adds d-bus signal based watch for software path interface add.
 *  @details This implements methods for watching for software path
 *  interface add signal and call appropriate function to initiate phal
 *  devtree attribute data collection and save to preserve partition.
 *  Rules:
 *   - Watch for interfaces added for the software path
 *   - If interface added is “Activation”
 *   - if Activation property value is “Ready”
 *   - Then software update is going to start
 *   - Collect phal devtree required attribute list and save to
 *     pre-defined location
 *
 */
class Watch
{
  public:
    Watch() = delete;
    ~Watch() = default;
    Watch(const Watch&) = delete;
    Watch& operator=(const Watch&) = delete;
    Watch(Watch&&) = default;
    Watch& operator=(Watch&&) = default;

    /** @brief constructs watch for interface add signals.
     *  @param[in] bus -  The Dbus bus object
     */

    Watch(sdbusplus::bus_t& bus) :
        addMatch(bus,
                 sdbusplus::bus::match::rules::interfacesAdded() +
                     sdbusplus::bus::match::rules::path(OBJ_SOFTWARE),
                 std::bind(std::mem_fn(&Watch::fwIntfAddedCallback), this,
                           std::placeholders::_1))
    {}

  private:
    /** @brief Method to check whether software update is in progress
     *  @return - bool
     */
    bool isSoftwareUpdateInProgress() const
    {
        return softwareUpdateInProgress;
    }

    /** @brief Method to indicate whether software update is in progress
     *
     *  @param[in] progress
     *
     */
    void setSoftwareUpdateProgress(bool progress)
    {
        softwareUpdateInProgress = progress;
    }

    /** @brief Callback function for software path add signal.
     *  @details Function provide required data related to new
     *  software path interface added to see software update progress.
     *
     *  @param[in] msg  - Data associated with subscribed signal
     */
    void fwIntfAddedCallback(sdbusplus::message_t& msg);

    /** @brief sdbusplus signal match for software path add */
    sdbusplus::bus::match_t addMatch;

    /** @brief indicates whether software update is going on */
    bool softwareUpdateInProgress = false;
};

/** @brief function to export phal devtree data file based
 * on the filter file,
 */
void exportDevtree();

} // namespace fwupdate
} // namespace phal
} // namespace openpower
