#ifndef _KVI_IRCMESSAGE_H_
#define _KVI_IRCMESSAGE_H_
//
//   File : kvi_ircmessage.h
//   Creation date : Fri Aug  2 23:08:55 2002 GMT by Szymon Stefanek
//
//   This file is part of the KVirc irc client distribution
//   Copyright (C) 2002 Szymon Stefanek (pragma at kvirc dot net)
//
//   This program is FREE software. You can redistribute it and/or
//   modify it under the terms of the GNU General Public License
//   as published by the Free Software Foundation; either version 2
//   of the License, or (at your opinion) any later version.
//
//   This program is distributed in the HOPE that it will be USEFUL,
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//   See the GNU General Public License for more details.
//
//   You should have received a copy of the GNU General Public License
//   along with this program. If not, write to the Free Software Foundation,
//   Inc. ,59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//

#define __KVIRC__

#include "kvi_settings.h"
#include "kvi_list.h"
#include "kvi_string.h"
#include "kvi_console.h"

#define KVI_IRCMSG_FLAG_HALTOUTPUT 1
#define KVI_IRCMSG_FLAG_UNRECOGNIZED 2

class KVIRC_API KviIrcMessage
{
public:
	KviIrcMessage(const char * message,KviConsole * console);
	~KviIrcMessage();
private:
	const char    * m_ptr;
	KviStr          m_szPrefix;
	KviStr          m_szCommand;
	KviPtrList<KviStr> * m_pParams;
	KviConsole    * m_pConsole;
	int             m_iNumericCommand;
	int             m_iFlags;
public:
	KviConsole   * console(){ return m_pConsole; };
//	KviWindow    * activeWindow(){ return m_pConsole->activeWindow(); };

	bool           isNumeric(){ return (m_iNumericCommand >= 0); };
	const char   * command(){ return m_szCommand.ptr(); };
	KviStr       * commandPtr(){ return &m_szCommand; };
	int            numeric(){ return m_iNumericCommand; };

	KviStr       * prefixPtr(){ return &m_szPrefix; };
	const char   * prefix(){ return m_szPrefix.ptr(); };
	const char   * safePrefix(){ return m_szPrefix.hasData() ? m_szPrefix.ptr() : m_pConsole->currentServerName(); };
	bool           hasPrefix(){ return m_szPrefix.hasData(); };


	int            paramCount(){ return m_pParams->count(); };

	const char   * param(unsigned int idx){ return (idx < m_pParams->count()) ? m_pParams->at(idx)->ptr() : 0; };
	const char   * safeParam(unsigned int idx){ return (idx < m_pParams->count()) ? m_pParams->at(idx)->ptr() : KviStr::emptyString().ptr(); };
	KviStr       * paramString(unsigned int idx){ return m_pParams->at(idx); };

	const char   * trailing(){ KviStr * tr = m_pParams->last(); return tr ? tr->ptr() : 0; };
	KviStr       * trailingString(){ return m_pParams->last(); };
	KviStr       & safeTrailingString(){ KviStr * tr = m_pParams->last(); return tr ? *tr : KviStr::emptyString(); };
	const char   * safeTrailing(){ KviStr * tr = m_pParams->last(); return tr ? tr->ptr() : KviStr::emptyString().ptr(); };

	const char   * allParams(){ return m_ptr; };

	KviStr       * firstParam(){ return m_pParams->first(); };
	KviStr       * nextParam(){ return m_pParams->next(); };

	void           setHaltOutput(){ m_iFlags |= KVI_IRCMSG_FLAG_HALTOUTPUT; };
	bool           haltOutput(){ return (m_iFlags & KVI_IRCMSG_FLAG_HALTOUTPUT); };
	void           setUnrecognized(){ m_iFlags |= KVI_IRCMSG_FLAG_UNRECOGNIZED; };
	bool           unrecognized(){ return (m_iFlags & KVI_IRCMSG_FLAG_UNRECOGNIZED); };
};

#endif //_KVI_IRCMESSAGE_H_
