(function () {
    'use strict';

    angular
        .module('app')
        .factory('UserService', UserService);

    UserService.$inject = ['$http'];
    function UserService($http) {
        var service = {};

        service.GetByEmail = GetByEmail;
        service.Create = Create;
       
        return service;


        function GetByEmail(email) {
            return $http.put('api/user.php', {email:email}).then(handleSuccess, handleError('Error getting user by email'));
        }

        function Create(user) {
            return $http.post('api/user.php', user).then(handleSuccess, handleError('Error creating user'));
        }


        // private functions

        function handleSuccess(res) {
            return res.data;
        }

        function handleError(error) {
            return function () {
                return { success: false, message: error };
            };
        }
    }

})();
