'user strict';

angular.module('roles.services', [
    'system'
])
.factory('RoleService', [ 
        '$http',
        '$q',
        function ($http, $q) {
            
            var URL = {
                ALL: '/qusion/api/roles/index',
                CREATE: '/qusion/api/roles/create',
                DELETE: '/qusion/api/roles/delete'
            };
            
            var all = function () {
                var deferred = $q.defer();
                $http.get(URL.ALL, {})
                    .success(function (data) {
                        deferred.resolve(data);
                    });
                return deferred.promise;
            };
            
            var create = function (role) {
                var deferred = $q.defer();
                $http.post(URL.CREATE, {role: role})
                    .success(function (data) {
                        deferred.resolve(data);
                    });
                return deferred.promise;
            };
           
            var remove = function (role) {
                var deferred = $q.defer();
                $http.post(URL.DELETE, {role: role})
                    .success(function (data) {
                        deferred.resolve(data);
                    });

                return deferred.promise;
            };
            
            return {
                all: all,
                create: create,
                remove: remove
            };
        }
])