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);

	}

}

