#pragma once

#include <map>
#include "halleystring.h"

namespace Halley {
	class ResourceData {
	public:
		ResourceData(void* data, size_t size, String path);
		~ResourceData();

		void* getData() { return data; }
		size_t getSize() const { return size; }
		String getPath() const { return path; }
		SDL_RWops* getRWOps();

	private:
		size_t size;
		void* data;
		String path;
	};

	class ResourceLocator {
	public:
		static void add(shared_ptr<ResourceLocator> locator);
		static shared_ptr<ResourceData> get(String resource);

		virtual ~ResourceLocator() {}

	protected:
		virtual shared_ptr<ResourceData> doGet(String resource)=0;
		virtual std::vector<String> getResourceList()=0;
		virtual int getPriority() { return 0; }

	private:
		static std::map<String, shared_ptr<ResourceLocator> > locators;
	};

	class FileSystemResourceLocator : public ResourceLocator {
	public:
		FileSystemResourceLocator(String basePath);

	protected:
		shared_ptr<ResourceData> doGet(String resource);
		std::vector<String> getResourceList();
		int getPriority() { return -1; }

		String basePath;
	};
}
