#pragma once

#include <filesystem>
#include <future>
#include <map>
#include <string>

class AvatarCache
{
public:
    explicit AvatarCache(const std::filesystem::path &user_data_directory);
    ~AvatarCache();

    AvatarCache(const AvatarCache &) = delete;
    AvatarCache &operator=(const AvatarCache &) = delete;

    unsigned int textureFor(const std::string &email);
    void update();
    void shutdown();

private:
    struct Entry
    {
        unsigned int texture = 0;
        bool requested = false;
        std::filesystem::path file;
        std::future<bool> download;
    };

    std::string hashEmail(const std::string &email) const;
    unsigned int loadTexture(const std::filesystem::path &file) const;
    std::filesystem::path directory_;
    std::map<std::string, Entry> entries_;
};
