/**********************************************************************
 * 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.
 **********************************************************************/

#pragma once

#include <boost/optional.hpp>
#include <QStringList>

namespace Media
{
	/** @brief Describes a lyrics search request.
	 *
	 * @sa ILyricsFinder
	 */
	struct LyricsQuery
	{
		/** @brief The artist preforming the track.
		 */
		QString Artist_;

		/** @brief The album this track is on.
		 */
		QString Album_;

		/** @brief The title of the track.
		 */
		QString Title_;

		/** @brief The year of the album the track is on.
		 */
		boost::optional<int> Year_;

		/** @brief The track number.
		 */
		boost::optional<int> Track_;
	};

	/** @brief Describes the various lyrics request options.
	 *
	 * @sa ILyricsFinder
	 */
	enum QueryOption
	{
		/** @brief Default lyrics search request.
		 */
		NoOption = 0x0,

		/** @brief Refresh any cached data.
		 */
		Refresh = 0x1
	};

	/** @brief Typedef for <code>QFlags<QueryOption></code>.
	 */
	Q_DECLARE_FLAGS (QueryOptions, QueryOption);

	/** @brief Describes a single lyrics result item.
	 *
	 * A result item is the lyrics themselves and the provider name these
	 * lyrics were fetched from.
	 *
	 * @sa LyricsResults
	 */
	struct LyricsResultItem
	{
		/** @brief The name of the provider lyrics were fetched from.
		 */
		QString ProviderName_;

		/** @brief The HTML-formatted lyrics string.
		 */
		QString Lyrics_;
	};

	/** @brief Describes the result set for a given lyrics query.
	 *
	 * The lyrics searching result set consists of the lyrics query and a
	 * list of lyrics results items.
	 *
	 * @sa LyricsResultItem.
	 */
	struct LyricsResults
	{
		/** @brief The original query these results are for.
		 */
		LyricsQuery Query_;

		/** @brief The list of found items for the Query_.
		 *
		 * This list may be empty or contain duplicate lyrics (though
		 * with different ProviderName_ fields).
		 */
		QList<LyricsResultItem> Items_;
	};

	/** @brief Interface for plugins supporting finding lyrics.
	 *
	 * Plugins that support searching for lyrics should implement this
	 * interface.
	 *
	 * Fetching lyrics is asynchronous in nature, so one should request
	 * fetching the lyrics via RequestLyrics() method and wait for the
	 * gotLyrics() signal with the corresponding query parameter.
	 *
	 * @todo Consider migrating to handle-based results, like for
	 * IArtistBioFetcher.
	 */
	class Q_DECL_EXPORT ILyricsFinder
	{
	public:
		virtual ~ILyricsFinder () {}

		/** @brief Requests searching for lyrics for the given query.
		 *
		 * @param[in] query The lyrics query.
		 * @param[in] options Additional search options.
		 */
		virtual void RequestLyrics (const LyricsQuery& query, QueryOptions options = NoOption) = 0;
	protected:
		/** @brief Emitted when search for lyrics is complete.
		 *
		 * It is OK to emit this signal multiple times for a single
		 * query.
		 *
		 * @param[out] results The results of the lyrics query,
		 * containing the original query and the actual results.
		 */
		virtual void gotLyrics (const LyricsResults& results) = 0;
	};
}

Q_DECLARE_INTERFACE (Media::ILyricsFinder, "org.LeechCraft.Media.ILyricsFinder/1.0")
