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

namespace DMX2
{
	public abstract class Sequenceur
	{

		static int idmax=0;

		public Sequenceur (int id)
		{
			this.id = id;
			idmax = Math.Max(id,idmax);
			Name = "Seq " + id.ToString();
		}

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

		int id;

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

		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 virtual void MajCircuitsSupprimes()
		{
		}*/

		public abstract void Save (XmlElement parent);

		public abstract void Command (string command);

	}

}

