//////////////////////////////////////////////////////////////////////////////
//
// Asura_DLC_System.h
//
// Copyright (c) 2009 Rebellion. All rights reserved.
//
// Description: This system gives a platform-independent structure for setting
//				up downloaded files for use in-game, and to access any online
//				services for obtaining these files. Unfortunately, owing to
//				the nature of these services most code is platform-specific.
//
//////////////////////////////////////////////////////////////////////////////

#ifdef ASURA_USE_PRAGMA_ONCE
    #pragma once
#endif

#ifndef ___ASURA_DLC_SYSTEM_H___
#define ___ASURA_DLC_SYSTEM_H___ 1

#ifdef ASURA_SUPPORT_DOWNLOADABLE_CONTENT

#include "Core/Asura_HashTree.h"

// Standard flags for file restrictions. Includes a reserved range so projects to set up their own.
enum ASURA_DLC_USAGE_RESTRICTION_FLAGS
{
	ASURA_DLC_USAGERESTRICTION_NOTYETPURCHASED	= 0x00000001,

	ASURA_DLC_USAGERESTRICTION_PROJECTRESERVED	= 0xFFFF0000,
};

// Base class for data to store in the downloaded files hash tree. Some platforms may need to subclass this for their own requirements, but the hash tree can take pointers to one of these.
class Asura_DLC_DownloadedFileData
{
public:
	Asura_DLC_DownloadedFileData(u_int uUsageRestrictions)
		: m_uUsageRestrictions(uUsageRestrictions)
	{
	}

	u_int GetUsageRestrictions() const { return m_uUsageRestrictions; }

private:
	u_int m_uUsageRestrictions;
};

class Asura_DLC_System
{
public:
	static void Initialise();
	static void Shutdown();

	static void UpdateDownloadedFiles();

	static bool IsNewContentAvailable();
	static void OpenStore();

	static bool									IsDownloadedFile(const char* szFile);
	static u_int								GetUsageRestrictions(const char* szFile);
	static const Asura_DLC_DownloadedFileData*	GetDownloadedFileData(const char* szFile); // Allows platform classes to get hold of any extra data their subclass of Asura_DLC_DownloadedFileData may have.

private:

	static void Platform_Initialise();
	static void Platform_Shutdown();

	static void Platform_UpdateDownloadedFiles();

	static bool Platform_IsNewContentAvailable();
	static void Platform_OpenStore();

	static void ClearDownloadedFileData();
	static void ClearDownloadedFileData_Callback(Asura_Hash_ID uHash, Asura_DLC_DownloadedFileData** ppxData);
	static void Platform_ClearDownloadedFileData();

	static Asura_TemplateHashTree<Asura_DLC_DownloadedFileData*> s_xDLCFiles;
};

#endif //#ifdef ASURA_SUPPORT_DOWNLOADABLE_CONTENT

#endif // #ifndef ___ASURA_DLC_SYSTEM_H___
