/**********************************************************************
 * LeechCraft - modular cross-platform feature rich internet client.
 * Copyright (C) 2006-2014  Georg Rudoy
 *
 * Boost Software License - Version 1.0 - August 17th, 2003
 *
 * Permission is hereby granted, free of charge, to any person or organization
 * obtaining a copy of the software and accompanying documentation covered by
 * this license (the "Software") to use, reproduce, display, distribute,
 * execute, and transmit the Software, and to prepare derivative works of the
 * Software, and to permit third-parties to whom the Software is furnished to
 * do so, all subject to the following:
 *
 * The copyright notices in the Software and this entire statement, including
 * the above license grant, this restriction and the following disclaimer,
 * must be included in all copies of the Software, in whole or in part, and
 * all derivative works of the Software, unless such copies or derivative
 * works are solely in the form of machine-executable object code generated by
 * a source language processor.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
 * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
 * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 **********************************************************************/

#include "adhoccommand.h"
#include <QtDebug>
#include <QDomElement>

namespace LeechCraft
{
namespace Azoth
{
namespace Xoox
{
	AdHocCommand::AdHocCommand (const QString& name, const QString& node)
	: Name_ { name }
	, Node_ { node }
	{
	}

	QString AdHocCommand::GetName () const
	{
		return Name_;
	}

	void AdHocCommand::SetName (const QString& name)
	{
		Name_ = name;
	}

	QString AdHocCommand::GetNode () const
	{
		return Node_;
	}

	void AdHocCommand::SetNode (const QString& node)
	{
		Node_ = node;
	}

	namespace
	{
		AdHocNote::Severity Type2Severity (const QString& severity)
		{
			if (severity == "info")
				return AdHocNote::Severity::Info;
			else if (severity == "warn")
				return AdHocNote::Severity::Warn;
			else if (severity == "error")
				return AdHocNote::Severity::Error;

			qWarning () << Q_FUNC_INFO
					<< "unknown severity level"
					<< severity;
			return AdHocNote::Severity::Info;
		}
	}

	AdHocNote::AdHocNote (const QDomElement& elem)
	: AdHocNote { elem.attribute ("type"), elem.text () }
	{
	}

	AdHocNote::AdHocNote (const QString& severity, const QString& text)
	: AdHocNote { Type2Severity (severity), text }
	{
	}

	AdHocNote::AdHocNote (Severity severity, const QString& text)
	: Severity_ { severity }
	, Text_ { text }
	{
	}

	AdHocNote::Severity AdHocNote::GetSeverity () const
	{
		return Severity_;
	}

	const QString& AdHocNote::GetText () const
	{
		return Text_;
	}

	QString AdHocResult::GetNode () const
	{
		return Node_;
	}

	void AdHocResult::SetNode (const QString& node)
	{
		Node_ = node;
	}

	QString AdHocResult::GetSessionID () const
	{
		return SessionID_;
	}

	void AdHocResult::SetSessionID (const QString& sid)
	{
		SessionID_ = sid;
	}

	QXmppDataForm AdHocResult::GetDataForm () const
	{
		return Form_;
	}

	void AdHocResult::SetDataForm (const QXmppDataForm& form)
	{
		Form_ = form;
	}

	QStringList AdHocResult::GetActions () const
	{
		return Actions_;
	}

	void AdHocResult::SetActions (const QStringList& actions)
	{
		Actions_ = actions;
	}

	const QList<AdHocNote>& AdHocResult::GetNotes () const
	{
		return Notes_;
	}

	void AdHocResult::AddNote (const AdHocNote& note)
	{
		Notes_ << note;
	}
}
}
}
