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

#ifndef PLUGINS_AGGREGATOR_INTERFACES_AGGREGATOR_FEED_H
#define PLUGINS_AGGREGATOR_INTERFACES_AGGREGATOR_FEED_H
#include <memory>
#include <vector>
#include <QString>
#include <QDateTime>
#include <QList>
#include <QMetaType>
#include "channel.h"
#include "common.h"

namespace LeechCraft
{
namespace Aggregator
{
	struct Feed
	{
		/** @brief Contains settings for a feed.
		 *
		 * If a feed overrides default settings like update timeout, number of
		 * stored items or max items age, this structure is used to store these
		 * settings in the storage backend.
		 *
		 * The feed can override only some of the settings, in this case others
		 * have setting-specific default value.
		 */
		struct FeedSettings
		{
			/** @brief ID of the corresponding feed.
			 */
			IDType_t FeedID_ = IDNotFound;

			/** @brief Update timeout for the feed.
			 *
			 * How often the feed should be checked for updates. The default
			 * value is 0.
			 */
			int UpdateTimeout_ = 0;

			/** @brief Max number of stored items.
			 *
			 * How much items should be stored in the feed's channels. The
			 * default value is 0.
			 */
			int NumItems_ = 0;

			/** @brief Max item's age.
			 *
			 * How old could be items in the feed. The default value is 0.
			 */
			int ItemAge_ = 0;

			/** @brief Automatically download enclosures.
			 *
			 * Whether Aggregator should automatically emit a
			 * gotEntity for each enclosure in each news item it
			 * fetches.
			 */
			bool AutoDownloadEnclosures_ = false;
		};

		IDType_t FeedID_;
		QString URL_;
		QDateTime LastUpdate_;
		channels_container_t Channels_;

		Feed ();
		Feed (const IDType_t& id);
	};

	typedef std::shared_ptr<Feed::FeedSettings> FeedSettings_ptr;
	typedef std::shared_ptr<Feed> Feed_ptr;
	typedef std::vector<Feed_ptr> feeds_container_t;
	typedef std::vector<QString> feeds_urls_t;

	bool operator< (const Feed& f1, const Feed& f2);
	QDataStream& operator<< (QDataStream&, const Feed&);
	QDataStream& operator>> (QDataStream&, Feed&);
}
}

Q_DECLARE_METATYPE (LeechCraft::Aggregator::Feed)

#endif
