//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using System.Collections;
using CommunityServer.Components;

namespace CommunityServer.Discussions.Components
{
	/// <summary>
	/// Base class for all Forum Syndication feeds
	/// </summary>
	public abstract class BaseForumSyndicationHandler : BaseSyndicationHandler
	{

		protected ForumConfiguration _forumConfig;
		protected ForumConfiguration ForumConfig
		{
			get
			{
				if (_forumConfig == null)
					_forumConfig = ForumConfiguration.Instance();

				return _forumConfig;
			}
		}

		public BaseForumSyndicationHandler()
		{
		}

		/// <summary>
		/// The length of time the feed should be cached in seconds.
		/// </summary>
		protected override int CacheTime
		{
			get
			{
				return CSCache.SecondFactorCalculate(ForumConfig.RssCacheWindowInSeconds);
			}
		}

		/// <summary>
		/// The Fully Qualifed part of the Url for the current request
		/// </summary>
		protected override string BaseUrl
		{
			get { return Globals.HostPath(Context.Request.Url); }
		}


		private Forum _forum;
		protected override Section GetCurrentSection
		{
			get
			{
				if(_forum == null)
				{
					_forum = Forums.GetForum(CSContext.Current.SectionID, true, false);
					if(_forum == null)
						throw new CSException(CSExceptionType.SectionNotFound,"The forum could not be found");

					Permissions.AccessCheck(_forum,Permission.Read,CSContext.Current.User);
				}
				return _forum;
			}
		}


	}
}
