(function () {
    "use strict";

    angular.module('pos').factory('usuarioService', factory);
    factory.$inject = ['$http', '$q'];

    function factory($http, $q) {

        var _save = function (vendedor) {
            var deferred = $q.defer();
            var args = {
                vendedor: vendedor,
            };
            $http.post('/usuario/save', args)
                .success(function (data) { deferred.resolve(data); })
                .error(function (data, status, headers, config) { deferred.reject(data); });
            return deferred.promise;
        }

        var _saveUserWithMail = function (vendedor) {
            var deferred = $q.defer();
            var args = {
                vendedor: vendedor,
            };
            $http.post('/usuario/saveuserwithmail', args)
                .success(function (data) { deferred.resolve(data); })
                .error(function (data, status, headers, config) { deferred.reject(data); });
            return deferred.promise;
        }

        var _validateMail = function (email) {
            var deferred = $q.defer();
            var args = {
                email: email,
            };
            $http.post('/usuario/validatemail', args)
                .success(function (data) { deferred.resolve(data); })
                .error(function (data, status, headers, config) { deferred.reject(data); });
            return deferred.promise;
        }

        return {
            save: _save,
            saveUserWithMail: _saveUserWithMail,
            validateMail: _validateMail,
        };
    }

})();