poconsole.factory('Config',function($q, $http, $log){
    var config = {};
    config.getConfig = function(){
        var deferred = $q.defer();
        $http.get('/api/configs').success(function(data) {
        	deferred.resolve({
    			config:data.objects
    		});
        });
        return deferred.promise;
    };

    config.submitParameter = function(entry){
        var deferred = $q.defer();
        $http.post('/api/configs', {
            parameter: entry.parameter,
            val: entry.val
        }).success(function(data){
            deferred.resolve({
    			data:data
    		});
        });
        return deferred.promise;
    };

    config.updateParameter = function(entry){
        var deferred = $q.defer();
        $http.put('/api/configs/' + entry._id, {
            parameter: entry.parameter,
            val: entry.val
        }).success(function(data){
            deferred.resolve({
    			data:data
    		});
        });
        return deferred.promise;
    };

    config.deleteParameter = function(id){
        var deferred = $q.defer();
        $http.delete('/api/configs/' + id).success(function(data){
            deferred.resolve({
    			data:data
    		});
        });
        return deferred.promise;
    };

    config.getLoggerStatus = function(){
        var deferred = $q.defer();
        $http.get('/api/logger_status').success(function(data) {
    		deferred.resolve(JSON.parse(data));
        });
        return deferred.promise;
    };

    config.restartLogger = function(){
        var deferred = $q.defer();
        $http.get('/api/restart_logger').success(function(data) {
        	deferred.resolve(data);
        });
        return deferred.promise;
    };

    return config;

});
