package de.dtele.net {
  
  import flash.utils.describeType;
  import flash.utils.getDefinitionByName;
  import flash.utils.getQualifiedClassName;
  
  import mx.controls.Alert;
  
  /**
   * Represents the API of defined MediaRequest errors
   * 
   * @author Mathias Brodala
   */
  public final class MediaRequestError {
    
    /* Constants */
    /**
     * An unknown error
     */
    public static const UNKNOWN:String = "unknown";
    /**
     * An unknown unknown protocol
     */
    public static const UNKNOWN_PROTOCOL:String = "unknownProtocol";
    /**
     * A protocol version not understood by the client or the source
     */
    public static const UNKNOWN_PROTOCOL_VERSION:String = "unknownProtocolVersion";
    /**
     * An unknown request type
     */
    public static const UNKNOWN_REQUEST_TYPE:String = "unknownRequestType";
    /**
     * The connection to a source has failed
     */
    public static const CONNECTION_FAILED:String = "connectionFailed";
    /**
     * The connection to a source was closed
     */
    public static const DISCONNECTED:String = "disconnected";
    /**
     * The source requests authentification data for access
     */
    public static const AUTHENTICATION_REQUIRED:String = "authenticationRequired";
    /**
     * The provided authentication data for access was not accepted
     */
    public static const AUTHENTICATION_FAILED:String = "authenticationFailed";
    /**
     * There where errors while processing the request
     */
    public static const MALFORMED_REQUEST:String = "malformedRequest";
    /**
     * There where errors while processing the response
     */
    public static const MALFORMED_RESPONSE:String = "malformedResponse";
    
    /* Properties */
    private var _code:String = MediaRequestError.UNKNOWN;
    /**
     * The unique code describing the MediaRequest error
     */
    public function get code():String { return _code; }

    private var _message:String = "Unbekannter Fehler";
    /**
     * A detailled description of the MediaRequest error 
     */
    public function get message():String { return _message; }
    
    /* Methods */
    public function MediaRequestError(code:String, message:String=null) {
      
      this._code = code;
      this._message = message;
      /*var description:XML = describeType(getDefinitionByName(getQualifiedClassName(this)));
      
      for each (var constant:XML in description.constant) {
        
        if (code == MediaRequestError[constant.@name]) {
          
          this._code = code;
          break;
        }
      }
      
      if (this._code == MediaRequestError.UNKNOWN) {
      }*/
    }
  }
}