//////////////////////////////////////////////////////////////////////////////
//
// Asura_PS3_NP_TUS.h
//
// Copyright (c) 2008 Rebellion. All rights reserved.
//
// Description:
//
//     wrappers for PS3 Title User Storage SDK
//
//////////////////////////////////////////////////////////////////////////////

// B E G I N   F I L E   W R A P P E R ///////////////////////////////////////

#ifdef ASURA_USE_PRAGMA_ONCE
    #pragma once
#endif

#ifndef ASURA_PS3_NP_TUS_H___
#define ASURA_PS3_NP_TUS_H___ 1

#include <np.h>

enum ASURA_PS3_TUS_DATA_SLOT
{
	ASURA_PS3_TUS_DATA_SLOT_LEADERBOARDS = 1,
	ASURA_PS3_TUS_DATA_SLOT_UNUSED = 2,			// previously used for merit - can be replaced.
	ASURA_PS3_TUS_DATA_SLOT_GAMECOMPLETION = 3,
};

enum ASURA_PS3_TUS_VAR_SLOT
{
	ASURA_PS3_TUS_VAR_SLOT_MERIT_LEVEL = 1,
	ASURA_PS3_TUS_VAR_SLOT_MERIT_POINTS = 2,
};

class Asura_PS3_NP_TUS
{
public:

	static void Initialise();
	static void Shutdown();

	static int GetTitleContext() { return s_iTitleContext; }

private:

	static int s_iTitleContext;
};


// Asura_PS3_TUSTransactionManagerBase - base class for Asura_PS3_TUSTransactionManagerData
// and Asura_PS3_TUSTransactionManagerVars
class Asura_PS3_TUSTransactionManagerBase
{
public:

	Asura_PS3_TUSTransactionManagerBase();
	virtual ~Asura_PS3_TUSTransactionManagerBase();

	bool Update();
	int GetOperationResult() const { return m_iResult; }
	bool HasErrorOccurred() const { return m_bError; }

	void SetError() { m_bError = true; }

protected:
	int CreateTransactionID();

	bool m_bError;
	int m_iTransactionID;
	int m_iResult;
};

class Asura_PS3_TUSTransactionManagerData : public Asura_PS3_TUSTransactionManagerBase
{
public:

	// wrapper functions for sceNpTusGetDataAsync/sceNpTusSetDataAsync() We assume that all writes will 
	// be for data packets small enough to read/write in one go so we don't need to worry about the API
	// for partial transfers.
	int GetDataAsync(const SceNpId& xTargetNpId, ASURA_PS3_TUS_DATA_SLOT eSlotID, void* pData, u_int uDataSize);
	int SetDataAsync(const SceNpId& xTargetNpId, ASURA_PS3_TUS_DATA_SLOT eSlotID, const void* pData, u_int uDataSize);
	bool IsDataValid(const char* m_pcData, u_int uExpectedDataSize) const;

private:

	SceNpTusDataStatus m_xDataStatus;
};

class Asura_PS3_TUSTransactionManagerGetVars : public Asura_PS3_TUSTransactionManagerBase
{
public:

	Asura_PS3_TUSTransactionManagerGetVars(u_int uMaxVarsToGet);
	~Asura_PS3_TUSTransactionManagerGetVars();

	// wrapper function for sceNpTusGetMultiSlotVariableAsync
	int GetVarsAsync(const SceNpId& xTargetNpId, u_int uNumVars, const ASURA_PS3_TUS_VAR_SLOT* aeSlotIDs);

	int64 GetVarValue(u_int uIndex) const;

private:

	SceNpTusVariable* m_pxVarArray;
	u_int m_uMaxVarsToGet;
};

class Asura_PS3_TUSTransactionManagerAddToVar : public Asura_PS3_TUSTransactionManagerBase
{
public:

	// wrapper function for sceNpTusAddAndGetVariableAsync().
	int AddToVarAsync(const SceNpId& xTargetNpId, ASURA_PS3_TUS_VAR_SLOT eSlotID, int64 lValueToAdd);

private:

	SceNpTusVariable m_xVarStorage;
};

class Asura_PS3_TUS_MeritData
{
public:

	u_int m_uMeritLevel;
	int m_iMeritPoints;
};


class Asura_PS3_TUS_GameCompletionData
{
public:
	// Ranked
	u_int m_uNumGamesHosted0;
	u_int m_uNumGamesStarted0;
	u_int m_uNumGamesCompleted0;

	// Friendly
	u_int m_uNumGamesHosted1;
	u_int m_uNumGamesStarted1;
	u_int m_uNumGamesCompleted1;
};

// E N D   F I L E   W R A P P E R ///////////////////////////////////////////

#endif // #ifndef ASURA_PS3_NP_TUS_H___
