#include "kms/kms_factory.hpp"
#include <stdexcept>

KmsFactory& KmsFactory::instance() {
    static KmsFactory factory;
    return factory;
}

void KmsFactory::registerCreator(const std::string& name, CreatorFunc func) {
    creators_[name] = std::move(func);
}

std::unique_ptr<IKmsCore> KmsFactory::create(const IKmsConfig& config) const {
    auto it = creators_.find(config.getType());
    if (it != creators_.end()) {
        return (it->second)(config);
    }
    throw std::runtime_error("KMS type not registered: " + config.getType());    
}

std::vector<std::string> KmsFactory::listRegistered() const {
    std::vector<std::string> names;
    for (const auto& [name, _] : creators_) {
        names.push_back(name);
    }
    return names;
}
