/**
 * An element which displays a user-friendly message for the current phase of a build.
 */
angular.module('quay').directive('buildMessage', function () {
  var directiveDefinitionObject = {
    priority: 0,
    templateUrl: '/static/directives/build-message.html',
    replace: false,
    transclude: false,
    restrict: 'C',
    scope: {
      'phase': '=phase'
    },
    controller: function($scope, $element) {
      $scope.getBuildMessage = function (phase) {
        switch (phase) {
          case 'cannot_load':
            return 'Cannot load build status - Please report this error';

          case 'starting':
          case 'initializing':
            return 'Starting Dockerfile build';

          case 'waiting':
            return 'Waiting for available build worker';

          case 'unpacking':
            return 'Unpacking build package';

          case 'pulling':
            return 'Pulling base image';

          case 'building':
            return 'Building image from Dockerfile';

          case 'checking-cache':
            return 'Looking up cached images';

          case 'priming-cache':
            return 'Priming cache for build';

          case 'build-scheduled':
            return 'Preparing build node';

          case 'pushing':
            return 'Pushing image built from Dockerfile';

          case 'complete':
            return 'Dockerfile build completed and pushed';

          case 'error':
            return 'Dockerfile build failed';

          case 'internalerror':
            return 'An internal system error occurred while building; the build will be retried in the next few minutes.';
        }
      };
    }
  };
  return directiveDefinitionObject;
});
