#pragma once

#include <boost/container/flat_map.hpp>
#include <sdbusplus/asio/connection.hpp>

#include <cstdlib>
#include <functional>
#include <memory>

namespace estoraged
{

using BasicVariantType =
    std::variant<std::vector<std::string>, std::string, int64_t, uint64_t,
                 double, int32_t, uint32_t, int16_t, uint16_t, uint8_t, bool>;

/* Map of properties for the config interface. */
using StorageData = boost::container::flat_map<std::string, BasicVariantType>;
using ManagedStorageType =
    boost::container::flat_map<sdbusplus::message::object_path, StorageData>;

const constexpr char* emmcConfigInterface =
    "xyz.openbmc_project.Configuration.EmmcDevice";

/** @class GetStorageConfiguration
 *  @brief Object used to find Entity Manager config objects.
 *  @details eStoraged will create a new D-Bus object for each config object.
 */
class GetStorageConfiguration :
    public std::enable_shared_from_this<GetStorageConfiguration>
{
  public:
    /** @brief Constructor for GetStorageConfiguration
     *
     *  @param[in] connection - shared_ptr to D-Bus connection object.
     *  @param[in] callbackFunc - callback to run after finding the config
     *    objects.
     */
    GetStorageConfiguration(
        std::shared_ptr<sdbusplus::asio::connection> connection,
        std::function<void(ManagedStorageType& resp)>&& callbackFunc) :
        dbusConnection(std::move(connection)),
        callback(std::move(callbackFunc))
    {}

    GetStorageConfiguration& operator=(const GetStorageConfiguration&) = delete;
    GetStorageConfiguration(const GetStorageConfiguration&) = delete;
    GetStorageConfiguration(GetStorageConfiguration&&) = default;
    GetStorageConfiguration& operator=(GetStorageConfiguration&&) = default;

    /** @brief Destructor for GetStorageConfiguration.
     *  @details This will execute the callback provided to the constructor.
     */
    ~GetStorageConfiguration();

    /** @brief Find the Entity Manager config objects for eStoraged. */
    void getConfiguration();

    /** @brief Get the D-Bus properties from the config object.
     *
     *  @param[in] path - D-Bus object path of the config object.
     *  @param[in] owner - D-Bus service that owns the config object.
     */
    void getStorageInfo(const std::string& path, const std::string& owner);

    /** @brief Map containing config objects with corresponding properties. */
    ManagedStorageType respData;

    /** @brief Connection to D-Bus. */
    std::shared_ptr<sdbusplus::asio::connection> dbusConnection;

  private:
    /** @brief callback to process the config object data in respData. */
    std::function<void(ManagedStorageType& resp)> callback;
};

} // namespace estoraged
