using System;
using skyscraper5.Dvb;
using skyscraper5.Skyscraper;

namespace skyscraper5.Mpeg2
{
    public abstract class TsDescriptor : Validatable
    {
	    public virtual byte GetDescriptorId()
	    {
		    Type type = this.GetType();
		    object[] customAttributes = type.GetCustomAttributes(false);
		    foreach (object customAttribute in customAttributes)
		    {
			    string name = customAttribute.GetType().Name;
			    switch (name)
			    {
					case "NullableContextAttribute": continue;
					case "NullableAttribute": continue;
					case "SkyscraperPluginAttribute": continue;
					case "UserDefinedDescriptorAttribute":
						UserDefinedDescriptorAttribute udda = (UserDefinedDescriptorAttribute)customAttribute;
						return udda.DescriptorId;
					case "TsDescriptorAttribute":
						TsDescriptorAttribute tda = (TsDescriptorAttribute)customAttribute;
						return tda.DescriptorId;
					default:
					    throw new NotImplementedException(name);
			    }
		    }
		    throw new NotImplementedException(String.Format("{0} does not reveal it's Descriptor ID"));
	    }

	    public virtual byte[] Serialize()
	    {
		    throw new NotImplementedException(String.Format("{0} does not implement Serialize()", this.GetType().Name));
	    }
    }
}
