#ifndef CONSOLE_H
#define CONSOLE_H

#include "engine.h"
#include "tier1/utlstring.h"
#include "tier1/utlvector.h"

class ConVar;
class ConCommand;

typedef void(*ConCommandFn)(int argc, char **argv);

interface IConsole
{
public:
	// Variables
	static void RegisterVar( ConVar *cvar );
	static void UnRegisterVar( ConVar *cvar );
	static ConVar *FindVar( const char *pName );

	// Commands
	static void RegisterCommand( ConCommand *cvar );
	static void UnRegisterCommand( ConCommand *cvar );
	static ConCommand *FindCommand( const char *pName );

	// Command buffer 
	static void Execute( void );
	static CUtlVector<CUtlVector<CUtlString>> ParseCommandLine( CUtlString psz );

	static void AddCommand( const char *psz );
	static void InsertCommand( const char *psz );
private:
	static void Execute2( CUtlVector<CUtlString> &args );
};


#define FCVAR_NONE 0
#define FCVAR_DEVELOPMENTONLY 0x1
#define FCVAR_GAMEDLL 0x2
#define FCVAR_CLIENTDLL 0x4
#define FCVAR_HIDDEN 0x8

#define FCVAR_PROTECTED 0x10
#define FCVAR_SPONLY 0x20
#define FCVAR_ARCHIVE 0x40
#define FCVAR_NOTIFY 0x80
#define FCVAR_CHEAT 0x100
#define FCVAR_REPLICATED 0x200

class ConVar
{
public:
	ConVar( const char *pName, const char *pDefaultValue, int flags );
	ConVar( const char *pName, const char *pDefaultValue, int flags,
		const char *pHelpString );
	ConVar( const char *pName, const char *pDefaultValue, int flags,
		const char *pHelpString, ConCommandFn callback );
	
	bool IsFlagSet( int flag );
	const char *GetHelpText( void );
	bool IsRegistered( void );
	const char *GetName( void );
	void AddFlags( int flags );
	bool IsCommand( void );

	void InstallChangeCallback( ConCommandFn );

	float GetFloat( void );
	int GetInt( void );
	bool GetBool( void );
	const char *GetString( void );

	void SetValue( const char *szValue );
	void SetValue( float fValue );
	void SetValue( int iValue );
private:
	CUtlString m_szName;
	CUtlString m_szHelpString;
	CUtlString m_szDefaultValue;

	CUtlString m_szValue;
	float m_fValue;
	int m_nValue;

	int m_flags;
};


class ConCommand
{
public:
	ConCommand(const char *pName, ConCommandFn callback, 
		const char *pHelpString=0, int flags=0);
	
	const char *GetName( void );
	const char *GetHelpText( void );
	ConCommandFn GetCallback( void );
private:
	CUtlString m_szName;
	CUtlString m_szHelpString = NULL;
	ConCommandFn m_callback;

	int m_flags;
};

void Msg( const char* message );
void Warning( const char* message );
void Error( const char* message );

#endif
