#pragma once

#include "config.h"

#include <sdbusplus/async.hpp>
#include <xyz/openbmc_project/Software/Update/server.hpp>

#include <random>
#include <string>
#include <tuple>

namespace phosphor::software::updater
{
class ItemUpdater;
}

namespace phosphor::software::update
{

using UpdateIntf = sdbusplus::server::object_t<
    sdbusplus::xyz::openbmc_project::Software::server::Update>;
using ItemUpdaterIntf = phosphor::software::updater::ItemUpdater;

using ApplyTimeIntf =
    sdbusplus::common::xyz::openbmc_project::software::ApplyTime;

/** @class Manager
 *  @brief Processes the image file from update D-Bus interface.
 *  @details The update manager class handles software updates and manages
 * software info through version and activation objects.
 */
class Manager : public UpdateIntf
{
  public:
    /** @brief Constructs Manager Class
     *
     * @param[in] bus - The Dbus bus object
     */
    explicit Manager(sdbusplus::async::context& ctx, const std::string& path,
                     ItemUpdaterIntf& itemUpdater) :
        UpdateIntf(ctx.get_bus(), path.c_str(), UpdateIntf::action::defer_emit),
        ctx(ctx), itemUpdater(itemUpdater)
    {
        emit_object_added();
    }

  private:
    /** @brief Implementation for StartUpdate
     *  Start a firware update to be performed asynchronously.
     */
    sdbusplus::message::object_path
        startUpdate(sdbusplus::message::unix_fd image,
                    ApplyTimeIntf::RequestedApplyTimes applyTime) override;

    /* @brief Process the image supplied via image fd */
    auto processImage(sdbusplus::message::unix_fd image,
                      ApplyTimeIntf::RequestedApplyTimes applyTime,
                      std::string id, std::string objPath)
        -> sdbusplus::async::task<>;

    /* @brief The handler for the image processing failure  */
    void processImageFailed(sdbusplus::message::unix_fd image, std::string& id);

    /** @brief The random generator for the software id */
    std::mt19937 randomGen{static_cast<unsigned>(
        std::chrono::system_clock::now().time_since_epoch().count())};

    /** @brief D-Bus context */
    sdbusplus::async::context& ctx;
    /** @brief item_updater reference */
    ItemUpdaterIntf& itemUpdater;
    /** @brief State whether update is in progress */
    bool updateInProgress = false;
};

} // namespace phosphor::software::update
