/**********************************************************************
 * 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 "astralityutil.h"
#include <Presence>
#include <interfaces/azoth/iclentry.h>

namespace LeechCraft
{
namespace Azoth
{
namespace Astrality
{
	State StateTelepathy2Azoth (Tp::ConnectionPresenceType type)
	{
		switch (type)
		{
		case Tp::ConnectionPresenceTypeOffline:
			return SOffline;
		case Tp::ConnectionPresenceTypeAvailable:
			return SOnline;
		case Tp::ConnectionPresenceTypeAway:
			return SAway;
		case Tp::ConnectionPresenceTypeBusy:
			return SDND;
		case Tp::ConnectionPresenceTypeExtendedAway:
			return SXA;
		case Tp::ConnectionPresenceTypeHidden:
			return SInvisible;
		case Tp::ConnectionPresenceTypeUnset:
		case Tp::ConnectionPresenceTypeUnknown:
		case Tp::ConnectionPresenceTypeError:
			return SInvalid;
		default:
			return SInvalid;
		}
	}

	Tp::ConnectionPresenceType StateAzoth2Telepathy (State state)
	{
		switch (state)
		{
		case SOffline:
			return Tp::ConnectionPresenceTypeOffline;
		case SOnline:
		case SChat:
			return Tp::ConnectionPresenceTypeAvailable;
		case SAway:
			return Tp::ConnectionPresenceTypeAway;
		case SDND:
			return Tp::ConnectionPresenceTypeBusy;
		case SXA:
			return Tp::ConnectionPresenceTypeExtendedAway;
		case SInvisible:
			return Tp::ConnectionPresenceTypeHidden;
		case SInvalid:
		case SProbe:
		case SConnecting:
			return Tp::ConnectionPresenceTypeUnknown;
		case SError:
			return Tp::ConnectionPresenceTypeError;
		default:
			return Tp::ConnectionPresenceTypeUnknown;
		}
	}

	Tp::Presence Status2Telepathy (const EntryStatus& status)
	{
		switch (status.State_)
		{
			case SOffline:
				return Tp::Presence::offline (status.StatusString_);
			case SOnline:
			case SChat:
				return Tp::Presence::available (status.StatusString_);
			case SAway:
				return Tp::Presence::away (status.StatusString_);
			case SDND:
				return Tp::Presence::busy (status.StatusString_);
			case SXA:
				return Tp::Presence::xa (status.StatusString_);
			case SInvisible:
				return Tp::Presence::hidden (status.StatusString_);
			default:
				return Tp::Presence ();
		}
	}

	EntryStatus Status2Azoth (const Tp::Presence& p)
	{
		return EntryStatus (StateTelepathy2Azoth (p.type ()), p.statusMessage ());
	}
}
}
}
