#pragma once

#include "ShaderTypes.h"

#include <filesystem>
#include <map>
#include <string>
#include <vector>

class ShaderPackageCatalog
{
public:
	struct Snapshot
	{
		std::map<std::string, ShaderPackage> packagesById;
		std::vector<std::string> packageOrder;
	};

	bool Scan(const std::filesystem::path& shaderRoot, unsigned maxTemporalHistoryFrames, std::string& error);
	Snapshot CaptureSnapshot() const;
	bool HasCatalogChangedSince(const Snapshot& snapshot) const;
	bool HasPackageChangedSince(const Snapshot& snapshot, const std::string& shaderId) const;
	bool HasPackage(const std::string& shaderId) const;
	const ShaderPackage* FindPackage(const std::string& shaderId) const;
	bool CopyPackage(const std::string& shaderId, ShaderPackage& shaderPackage) const;
	const std::vector<std::string>& PackageOrder() const;
	const std::vector<ShaderPackageStatus>& PackageStatuses() const;

private:
	static bool PackagesEquivalent(const ShaderPackage& left, const ShaderPackage& right);
	static bool TextureAssetsEqual(const std::vector<ShaderTextureAsset>& left, const std::vector<ShaderTextureAsset>& right);
	static bool FontAssetsEqual(const std::vector<ShaderFontAsset>& left, const std::vector<ShaderFontAsset>& right);

	std::map<std::string, ShaderPackage> mPackagesById;
	std::vector<std::string> mPackageOrder;
	std::vector<ShaderPackageStatus> mPackageStatuses;
};
