/******************************************************************************
*	File		-	asset_index.h
*	Author		-	Joey Pollack
*	Date		-	2021/10/25 (y/m/d)
*	Mod Date	-	2021/10/25 (y/m/d)
*	Description	-	Loads and stores the index.dat file. Allows querying
*                   the asset index by asset ID or name.
******************************************************************************/

#ifndef ASSET_INDEX_H_
#define ASSET_INDEX_H_

#include <core/common_defs.h>
#include <core/types.h>
#include <utils/op_res.h>
#include <assets/types/asset.h>

#include <string>
#include <map>

namespace lunarium
{
    class AssetIndex
    {
    public:
        struct AssetInfo
        {
            int32_t ID;
            std::string Name;
            AssetType Type;
            std::string File;       // The data file the asset is stored in
            u32 Offset;             // The offset into the file at which the asset can be found
        };

    public:

        static AssetIndex& GetInstance();
        static void FreeInstance();

        OpRes LoadIndex(const char* filename);
        const AssetInfo* GetAssetInfo(int id) const;
        const AssetInfo* GetAssetInfo(const char* name) const;


    private:
        static AssetIndex* mpInstance;
        std::map<int, AssetInfo*> mAssets;
        std::map<std::string, AssetInfo*> mAssetsByName;

        AssetIndex();
        AssetIndex(const AssetIndex&) = delete;
        AssetIndex& operator=(const AssetIndex&) = delete;
    };
}

#endif  // ASSET_INDEX_H_
