#pragma once

#include <string>
#include <unordered_map>
#include <mutex>
#include <openssl/ssl.h>

class CertManager
{
    public:
        CertManager();
        ~CertManager();

        bool Init();
        SSL_CTX* CreateHostContext(const std::string& host);

    private:
        bool GenerateCA();
        bool LoadCA();

        EVP_PKEY* _caPkey = nullptr;
        X509* _caCert = nullptr;
        EVP_PKEY* _sessionPkey = nullptr;

        std::mutex _mutex;
        std::unordered_map<std::string, SSL_CTX*> _hostContexts;
};
