(function(){
  'use strict';

  angular.module('users')
         .service('workflowService', ['$q', '$fsm', WorkflowService]);

  /**
   * Users DataService
   * Uses embedded, hard-coded data model; acts asynchronously to simulate
   * remote data service call(s).
   *
   * @returns {{loadAll: Function}}
   * @constructor
   */
  function WorkflowService($q, $fsm){
    
    var events = [
        { name: 'next',  from: 'start',  to: 'log_in' },
        { name: 'next', from: 'log_in', to: 'pick_school' },
        { name: 'next',  from: 'pick_school', to: 'get_phone' },
        { name: 'next',  from: 'get_phone', to: 'get_question-1' },
        { name: 'next',  from: ['get_question-1'], to: 'finish' },
        // { name: 'next',  from: '*', to: 'start' },
        { name: 'reset',  from: '*', to: 'start' }
    ];

    var fsm = $fsm.create({
      initial: 'start',
      events: events
    });
    
    fsm.onenterstate = function (event, from, to, deferred, args) {
      deferred.resolve([fsm.current, args]);  
    };
    
    fsm.onleavepick_school = function (event, from, to, deferred, args) {
        // return false;
    };

    return {
        'next': function (args) {
          var deferred = $q.defer();
          fsm.next(deferred, args);
          return [deferred.promise, fsm.can('next')];
        }
    }
  }

})();

@@ -1008,20 +1008,32 @@
 urrent, 
-args
+ fsm.can('next')
 %5D);  %0A  
@@ -1140,16 +1140,20 @@
 n false;
+    
 %0A    %7D;%0A
@@ -1290,17 +1290,16 @@
  return 
-%5B
 deferred
@@ -1310,26 +1310,8 @@
 mise
-, fsm.can('next')%5D
 ;%0A  

return promise