//
//  ExtensionManager.hpp
//  SwitchboardSDK
//
//  Created by Balazs Kiss on 30/08/2024.
//

#pragma once

#include <switchboard/export.h>
#include <switchboard_core/Extension.hpp>
#include <map>
#include <string>

namespace switchboard {

/**
 * @brief Manages the extensions of the Switchboard SDK.
 */
class SWITCHBOARDSDK_EXPORT ExtensionManager final {
public:
    /**
     * @brief Gets the shared instance of the ExtensionManager.
     */
    static ExtensionManager& getInstance();

    /**
     * @brief Registers an extension.
     *
     * @param extension The extension to register.
     */
    void registerExtension(std::shared_ptr<Extension> extension);

    /**
     * @brief Initializes an extension with the given configuration.
     *
     * @param extensionName The name of the extension to initialize.
     * @param config The configuration parameters for the extension.
     * 
     * @return Result<void> Success if the extension was initialized, error otherwise.
     */
    Result<void> initializeExtension(const std::string& extensionName, const SBAnyMap& config);

    /**
     * @brief Deinitializes an extension.
     *
     * @param extensionName The name of the extension to deinitialize.
     * 
     * @return Result<void> Success if the extension was deinitialized, error otherwise.
     */
    Result<void> deinitializeExtension(const std::string& extensionName);

private:
    static ExtensionManager* sharedInstance;

    std::map<std::string, std::shared_ptr<Extension>> extensions;
};

}
