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

using System;
using System.Collections;
using System.Xml;
using CommunityServer.Components;
using CommunityServer.Blogs.Components;

namespace CommunityServer.Spam
{
	/// <summary>
	/// Summary description for SpamConfiguration.
	/// </summary>
	[Serializable]
	public class SpamConfiguration : ApplicationConfiguration
	{

		#region Constructor & Instance

		private static readonly Type thisType = typeof(SpamConfiguration);

		public static SpamConfiguration Instance()
		{
			return Instance(true);
		}
		
		public static SpamConfiguration Instance(bool useCache)
		{
			return Instance(thisType, useCache) as SpamConfiguration;
		}

		public SpamConfiguration()
		{
		}

		#endregion

		protected override string ConfigSection
		{
			get { return "CommunityServer/Spam"; }
		}


		public override ApplicationType ApplicationType
		{
			get { return ApplicationType.Spam; }
		}

		protected override void Initialize(XmlNode node)
		{
			base.Initialize(node);

			if(node != null)
			{
				XmlAttributeCollection attcol = node.Attributes;
				XmlAttribute attrib;

				attrib = attcol["enableSpamScoreAudit"];
				if(attrib != null)
					this._defaultEnableSpamScoreAudit = Boolean.Parse(attrib.Value);

				attrib = attcol["autoModerateScore"];
				if(attrib != null)
					this._defaultAutoModerateScore = Int32.Parse(attrib.Value);

				attrib = attcol["autoDeleteScore"];
				if(attrib != null)
					this._defaultAutoDeleteScore = Int32.Parse(attrib.Value);
			}
		}


		#region Properties

		/// <summary>
		/// Should each rules score be added to post's spam score audit
		/// </summary>
		private bool _defaultEnableSpamScoreAudit = false;
		public bool EnableSpamScoreAudit
		{
			get { return _defaultEnableSpamScoreAudit; }
			set { _defaultEnableSpamScoreAudit = value; }
		}

		/// <summary>
		/// Score above which a post is auto-moderated (integer)
		/// </summary>
		private int _defaultAutoModerateScore = 5;
		public int AutoModerateScore
		{
			get {  return _defaultAutoModerateScore; }
			set { _defaultAutoModerateScore = value; }
		}

		/// <summary>
		/// Score above which a post is auto-deleted (integer)
		/// </summary>
		private int _defaultAutoDeleteScore = 10;
		public int AutoDeleteScore
		{
			get {  return _defaultAutoDeleteScore; }
			set { _defaultAutoDeleteScore = value; }
		}

		/// <summary>
		/// A list of spam rules
		/// </summary>
		private string[] _rules;
		public string[] Rules
		{
			get {  return _rules; }
			set { _rules = value; }
		}

		/// <summary>
		/// A table of spam rule settings, with the rule id Guid as the key
		/// </summary>
		private RuleSetting[] _ruleSettings;
		public RuleSetting[] RuleSettings
		{
			get {  return _ruleSettings; }
			set { _ruleSettings = value; }
		}

		#endregion
	}
}
