/**
 * Service which exposes various methods for creating entities on the backend.
 */
angular.module('quay').factory('CreateService', ['ApiService', function(ApiService) {
  var createService = {};

  createService.createRobotAccount = function(ApiService, is_org, orgname, name, callback) {
    ApiService.createRobot(is_org ? orgname : null, null, {'robot_shortname': name})
              .then(callback, ApiService.errorDisplay('Cannot create robot account'));
  };

  createService.createOrganizationTeam = function(ApiService, orgname, teamname, callback) {
    var data = {
      'name': teamname,
      'role': 'member'
    };

    var params = {
      'orgname': orgname,
      'teamname': teamname
    };

    ApiService.updateOrganizationTeam(data, params)
              .then(callback, ApiService.errorDisplay('Cannot create team'));
  };

  return createService;
}]);