#region Copyright and GPL
/*************************************************************************
 * dataMagus - The open source database learning software
 * Copyright (C) 2007 by all authors
 * Authors: Monika Schwitter (monsy@gmx.ch)
 *          Jürg Zgraggen (j.zgraggen@ejaz.net)
 *          HSLU (Hochschule Luzern - Technik+Architektur)
 * 
 *     This program is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 * 
 *     This program is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU General Public License for more details.
 * 
 *     You should have received a copy of the GNU General Public License
 *     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *************************************************************************/
#endregion
#region Using
using System;
using System.Runtime.Serialization;
using System.Xml.Serialization;
#endregion

namespace dataMagus.Common
{
	#region Delegates
	/// <summary>
	/// Handler when a schema has been changed.
	/// </summary>
	public delegate void SchemaChangedHandler(object sender, SchemaEventArgs e);
	#endregion
	
	#region Enumerators
	/// <summary>
	/// Change action on the schema.
	/// </summary>
	public enum SchemaChangedAction
	{
		/// <summary>
		/// Undefined
		/// </summary>
		Undefined,
		
		/// <summary>
		/// ChangedProperty
		/// </summary>
		ChangedProperty,
		
		/// <summary>
		/// AddedElement
		/// </summary>
		AddedElement,
		
		/// <summary>
		/// RemovedElement
		/// </summary>
		RemovedElement,
		
		/// <summary>
		/// RebuildedSchema
		/// </summary>
		RebuildedSchema,
		
		/// <summary>
		/// ExchangeSchema
		/// </summary>
		ExchangeSchema
	}
	#endregion
	
	/// <summary>
	/// Event argument data for SchemaChangedHandler.
	/// </summary>
	public class SchemaEventArgs : EventArgs
	{
		#region Members
		/// <summary>
		/// The scheman on which the action happend. 
		/// </summary>
		private ISchema _schema = null;
		
		/// <summary>
		/// The Element which resulted out of the action.
		/// </summary>
		private IElement _element = null;
		
		/// <summary>
		/// The action which happend on the schema.
		/// </summary>
		private SchemaChangedAction _action = SchemaChangedAction.Undefined;
		#endregion
		
        #region Constructors / Destructors
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="schema">The scheman on which the action happend.</param>
        /// <param name="action">The action which happend on the schema.</param>
		public SchemaEventArgs(ISchema schema, SchemaChangedAction action)
			: this(schema, action, null)
		{
		}
		
		/// <summary>
        /// Constructor.
		/// </summary>
		/// <param name="schema">The scheman on which the action happend.</param>
		/// <param name="action">The action which happend on the schema.</param>
		/// <param name="element">The Element which resulted out of the action.</param>
		public SchemaEventArgs(ISchema schema, SchemaChangedAction action, IElement element)
		{
			this._schema = schema;
			this._element = element;
			this._action = action;
		}
        #endregion

        #region Properties
        /// <summary>
        /// The scheman on which the action happend.
        /// </summary>
		public ISchema Schema 
		{
			get { return this._schema; }
		}
		
		/// <summary>
		/// The Element which resulted out of the action.
		/// </summary>
		public IElement Element 
		{
			get { return this._element; }
		}
		
		/// <summary>
		/// The action which happend on the schema.
		/// </summary>
		public SchemaChangedAction Action 
		{
			get { return this._action; }
		}
        #endregion
	}

	/// <summary>
	/// This interface defines a schema.
	/// </summary>
	public interface ISchema : ICloneable
	{
		#region Properties
		/// <summary>
		/// Id of the schema.
		/// </summary>
		string Id	{ get; }
		
		/// <summary>
		/// Name of the schema.
		/// </summary>
		string Name { get; set; }
        
		/// <summary>
		/// Current selected notation type.
		/// </summary>
		Type NotationType { get; set; }
		
		/// <summary>
		/// Indicates if the element is in InitMode.
		/// </summary>
		/// <remarks>InitMode will suppress all changing events.</remarks>
		bool InitMode { get; }
		
		/// <summary>
		/// Indicates if the element has been cloned.
		/// </summary>
        /// <remarks>Beware: events on clones will be suppressed.</remarks>
		bool IsClone { get; }
		#endregion
		
		#region Events
		/// <summary>
		/// Event when the schema has been changed.
		/// </summary>
		event SchemaChangedHandler SchemaChanged;
		#endregion
		
		#region Methodes
		/// <summary>
		/// Begin initialization mode.
		/// </summary>
		/// <remarks>Prevents event handling.</remarks>
        void BeginInit();
        
		/// <summary>
		/// End initialization mode.
		/// </summary>
		/// <remarks>Event handling will continue.</remarks>
		/// <param name="forceEvent">Indicates if an Undefined event has to be fired to inform other listeners.</param>
        void EndInit(bool forceEvent);
		
        /// <summary>
        /// Fires an schema changed event.
        /// </summary>
        /// <param name="sender">Sender object.</param>
        /// <param name="args">Action on the schema.</param>
        void FireSchemaChangedEvent(object sender, SchemaEventArgs args);
		#endregion
	}
}
