angular.module('app.services', [])

.factory('BlankFactory', [function(){

}])
.service('ServiceClient',['$http','$q',function($http,$q){
	
    this.authenticate=function(mail,password){
        var deferred=$q.defer();
        var data = $.param({'mail':mail,'password':password});
        $http.post('http://localhost:8080/client/auth',data,
        {headers: {'Content-Type': 'application/x-www-form-urlencoded'}}).
        success(function(data){
            deferred.resolve(data);
        });
        return deferred.promise;
    }
    this.inscrire = function(newClient){
         var deferred=$q.defer();
        var data = $.param(newClient);
        $http.post('http://localhost:8080/client/add',data,
        {headers: {'Content-Type': 'application/x-www-form-urlencoded'}}).
        success(function(data){
            deferred.resolve(data);
        });
        return deferred.promise;
    }
	
}])
.service('ServiceLivre',['$http','$q',function($http,$q){
	
	this.getByMC=function(mc,page,size){
		var deferred=$q.defer();
        $http.get('http://localhost:8080/livre/'+mc+'?page='+page+'&size='+size).
        success(function(data){
            deferred.resolve(data);
        });
        return deferred.promise;
	}
	
	this.getByTheme=function(idTheme,page,size){
		var deferred=$q.defer();
        $http.get('http://localhost:8080/livre/theme/'+idTheme+'?page='+page+'&size='+size).
        success(function(data){
            deferred.resolve(data);
        });
        return deferred.promise;
	}
	this.getByCategory=function(idCategory,page,size){
		var deferred=$q.defer();
        $http.get('http://localhost:8080/livre/category/'+idCategory+'?page='+page+'&size='+size).
        success(function(data){
            deferred.resolve(data);
        });
        return deferred.promise;
	}
	this.getBySubCategory=function(idSubCategory,page,size){
		var deferred=$q.defer();
        $http.get('http://localhost:8080/livre/subCategory/'+idSubCategory+'?page='+page+'&size='+size).
        success(function(data){
            deferred.resolve(data);
        });
        return deferred.promise;
	}
}])
.service('ThemeService',['$http','$q',function($http,$q){
	
	this.all=function(){
		var deferred=$q.defer();
        $http.get('http://localhost:8080/theme/').
        success(function(data){
            deferred.resolve(data);
        });
        return deferred.promise;
	}
    this.get=function(id){
		var deferred=$q.defer();
        $http.get('http://localhost:8080/theme/'+id).
        success(function(data){
            deferred.resolve(data);
        });
        return deferred.promise;
	}
}]);