#pragma once
#include <string>
#include <unordered_map>
#include <mutex>
#include <vector>
#include <future>
#include <yaml-cpp/yaml.h>
#include "../types/vec2.h"
#include <GL/glew.h>


enum class AssetType { Image, Audio };

struct AssetInfo
{
    uint64_t uaid;
    std::string path;
    std::string filename;
    std::string filetype;
    AssetType type;
    core::types::Vec2 size;

    std::string hash;
    int channels = 4;
    std::string format;
    std::time_t lastModified = 0;


    bool loaded = false;
    GLuint textureID = 0;
};

class AssetManager
{
public:
    static void Init();
    static void LoadAssetAsync(const std::string& path, AssetType type);
    static const AssetInfo* GetAssetByID(uint64_t uaid);
    static const AssetInfo* GetAssetByPath(const std::string& path);
    static const std::unordered_map<uint64_t, AssetInfo>& GetAllAssets();

    static void UnloadAsset(uint64_t uaid);
    static void ClearAllAssets();

    static void Save(YAML::Emitter& out);
    static void Load(const YAML::Node& node);


private:
    static std::unordered_map<uint64_t, AssetInfo> s_Assets;
    static std::unordered_map<std::string, uint64_t> s_PathToUAID;
    static uint64_t s_NextUAID;

    static uint64_t GenerateUAID();
    static void LoadImageInternal(const std::string& path, uint64_t uaid);
};
