poconsole.factory('config',function($q, $http, $log){

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

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

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

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

    var getLoggerStatus = function(){
        var deferred = $q.defer();
        $http.get('/logger_status').success(function(data) {
    		deferred.resolve({
    			pid:data.pid,
    			status: data.status
    		});
        });
        return deferred.promise;
    };

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


    return {
        getConfig:getConfig,
        submitParameter: submitParameter,
        getLoggerStatus: getLoggerStatus,
        restartLogger: restartLogger,
        updateParameter: updateParameter,
        deleteParameter: deleteParameter

    };

});
