/** @file navobject.cpp
 *  An implementation of INav from an Object
 *	@headerfile luanav.h "EANav/luanav.h"
 *	@author Chris Burns (cburns@ea.com)
 *
 *	UX
 *	(c) 2012 Electronic Arts Inc.
 */

#include "EANav/navobject.h"

#include "EABaseTypes/datatypes.h"
#include "EABaseTypes/functioncallwrappers.h"

namespace EA
{
	namespace Nav
	{
		NavObject::NavObject():
			mObject(NULL)
		{
		}

		NavObject::~NavObject()
		{
		}

		void NavObject::SetObject(EA::Types::ObjectIn object)
		{
			mObject = object;
		}

		/* virtual */ EA::Types::ObjectReturn NavObject::ToObject()
		{
			return mObject;
		}

		/* virtual */ void NavObject::Start(EA::Types::FunctionIn callback)
		{
			(*mObject)["Start"]->AsFunction()->Call<void>(callback);
		}

		/* virtual */ void NavObject::Event(EA::Types::FunctionIn callback, const char* name, EA::Types::BaseTypeIn data)
		{
			(*mObject)["Event"]->AsFunction()->Call<void>(callback, name, data);
		}

		/* virtual */ void NavObject::AddActionHandler(const char* name, bool async, EA::Types::ArrayIn read, EA::Types::FunctionIn handler)
		{
			(*mObject)["AddActionHandler"]->AsFunction()->Call<void>(name, async, read, handler);
		}

		/* virtual */ void NavObject::AddActionHandler(const char* name, bool async, const char** read, EA::Types::FunctionIn handler)
		{
			(*mObject)["AddActionHandler"]->AsFunction()->Call<void>(name, async, read, handler);
		}

		/* virtual */ void NavObject::RemoveActionHandler(const char* name)
		{
			(*mObject)["RemoveActionHandler"]->AsFunction()->Call<void>(name);
		}

		/* virtual */ void NavObject::SetLoadFailureHandler(EA::Types::FunctionIn handler)
		{
			(*mObject)["SetLoadFailureHandler"]->AsFunction()->Call<void>(handler);
		}
	
		/* virtual */ void NavObject::SaveConfiguration(EA::Types::FunctionIn callback)
		{
			(*mObject)["SaveConfiguration"]->AsFunction()->Call<void>(callback);
		}
	
		/* virtual */ void NavObject::LoadConfiguration(EA::Types::FunctionIn callback, EA::Types::BaseTypeIn configuration)
		{
			(*mObject)["LoadConfiguration"]->AsFunction()->Call<void>(callback, configuration);
		}

        /* virtual */ void NavObject::AddListener(const char* name, EA::Types::ArrayIn filter, EA::Types::FunctionIn listener)
		{
			(*mObject)["AddListener"]->AsFunction()->Call<void>(name, filter, listener);
		}

		/* virtual */ void NavObject::AddListener(const char* name, const char** filter, EA::Types::FunctionIn listener)
		{
			(*mObject)["AddListener"]->AsFunction()->Call<void>(name, filter, listener);
		}

		/* virtual */ void NavObject::RemoveListener(const char* name)
		{
			(*mObject)["RemoveListener"]->AsFunction()->Call<void>(name);
		}
        
#if !defined(EA_FINAL)

		/* virtual */ void NavObject::GetStates(EA::Types::FunctionIn callback)
		{
			(*mObject)["GetStates"]->AsFunction()->Call<void>(callback);
		}

		/* virtual */ void NavObject::GetTransitionEvents(EA::Types::FunctionIn callback)
		{
			(*mObject)["GetTransitionEvents"]->AsFunction()->Call<void>(callback);
		}

		/* virtual */ void NavObject::Auto(EA::Types::FunctionIn callback, 
										   EA::Types::FunctionIn defaultHandler, 
										   const char* hintFile, 
										   const char* excludeFile, 
										   EA::Types::ArrayIn targets, 
										   int maxNodes)
		{
			(*mObject)["Auto"]->AsFunction()->Call<void>(callback, defaultHandler, hintFile, excludeFile, targets, maxNodes);
		}

		/* virtual */ void NavObject::AddAutoHandler(const char* name, EA::Types::FunctionIn handler)
		{
			(*mObject)["AddAutoHandler"]->AsFunction()->Call<void>(name, handler);
		}

		/* virtual */ void NavObject::RemoveAutoHandler(const char* name)
		{
			(*mObject)["RemoveAutoHandler"]->AsFunction()->Call<void>(name);
		}
        
        /* virtual */ void NavObject::GetConfiguration(EA::Types::FunctionIn callback)
        {
            (*mObject)["GetConfiguration"]->AsFunction()->Call<void>(callback);
        }
        
        /* virtual */ void NavObject::Reload(EA::Types::FunctionIn callback, const char* name)
        {
            (*mObject)["Reload"]->AsFunction()->Call<void>(callback, name);
        }

#endif // !EA_FINAL
	}
}
