#pragma once

#include <string>
#include <unordered_map>
#include <mutex>
#include <memory>

namespace node669427 {

class Vault {
public:
    Vault(const std::string& vault_path, const std::string& key_path);
    ~Vault();

    bool initialize();
    std::string get(const std::string& key) const;
    std::string getOrDefault(const std::string& key, const std::string& default_val) const;
    bool has(const std::string& key) const;
    void refresh();
    size_t size() const;

private:
    std::string vault_path_;
    std::string key_path_;
    std::unordered_map<std::string, std::string> cache_;
    mutable std::mutex cache_mutex_;

    std::string decryptFile(const std::string& file_path) const;
    void scanAndDecrypt();
};

using VaultPtr = std::shared_ptr<Vault>;

} // namespace node669427
