/* 

   Copyright (C) Arnaud Houdelette		2012-2014
   Copyright (C) Emmanuel Langlois		2012-2014

   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 2 of the License.
   
   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/>.
*/

using System;
using System.Collections.Generic;
using System.Xml;

namespace DMX2
{
	public abstract class Sequenceur
	{

		public static int maxid=1;

		public Sequenceur ()
		{
			id = maxid++;
			Name = "Seq " + id.ToString();
		}

		int id;

		public int ID {
			get {
				return id;
			}
			protected set {
				id=value;
				maxid = Math.Max(id+1,maxid);
			}
		}

		string name;

		public string Name {
			get {
				return name;
			}
			set {
				name = value;
				if(Renamed!=null) Renamed(this, new SeqRenamedEventArgs(value));
			}
		}


		public sealed class SeqRenamedEventArgs : EventArgs
		{
			public SeqRenamedEventArgs (string name)
			{
				NewName = name;
			}
			public string NewName {get;private set;}
		}

		public event EventHandler<SeqRenamedEventArgs> Renamed;

		public abstract SequenceurUI GetUI();

		public abstract int ValeurCircuit(Circuit c);

		public abstract void Tick(TimeSpan time);

		public static Sequenceur Load (Conduite conduite, XmlElement el)
		{
			switch (el.Name) {
			case "SequenceurLineaire":
				return SequenceurLineaire.Load(conduite, el);
			case "SequenceurMacro":
				return SequenceurMacro.Load(conduite,el);
			}
			return null;
		}

		public abstract void Save (XmlElement parent);

		public abstract void Command (string command);

	}

}

