package de.dtele.control.events {
  
  import de.dtele.data.ISource;
  import de.dtele.net.MediaRequest;
  
  import flash.events.Event;
  
  /**
   * Allows for exchanging credentials
   * 
   * @author Mathias Brodala <mathias.brodala@dtele.de>
   */
  public class CredentialsEvent extends Event {
    
    /* Constants */
    /**
     * The CredentialsEvent.REQUEST constant defines the value of the 
     * <code>type</code> property of the event object 
     * for a <code>credentialsRequest</code> event.
     * 
     * @eventType credentialsRequest
     */
    public static const REQUEST:String = "credentialsRequest";
    
    /* Properties */
    private var _source:ISource;
    /**
     * The source this event was dispatched for
     */
    public function get source():ISource { return this._source; }
    
    private var _request:MediaRequest;
    /**
     * The request to the source this event was dispatched for
     */
    public function get request():MediaRequest { return this._request; }
    
    private var _callback:Function;
    /**
     * The callback function to return credentials to the requester
     * 
     * <p>The credentials must be provided via the callback function as follows:</p>
     * <pre><code>
     *     callback(credentials);
     * </code></pre>
     */
    public function get callback():Function { return this._callback; }
    
    /* Methods */
    public function CredentialsEvent(type:String, source:ISource, request:MediaRequest, callback:Function) {
      
      super(type, /*bubbles = */ true, /* cancelable = */ true);
      
      this._source = source;
      this._request = request;
      this._callback = callback;
    }
  }
}