poconsole.factory('WellTest',function($q, $http, $log){
	var service = {};
	service.getWellTestPage = function(page_number) {
        var deferred = $q.defer();
        $http.get('/api/well_tests?q={"order_by":[{"field":"created_on","direction":"desc"}]}&page=' + page_number).success(function(data) {
        	deferred.resolve(data);
        });
        return deferred.promise;
    };

    service.getWellTest = function(id){
        var deferred = $q.defer();
        $http.get('/api/well_tests/' + id).success(function(data) {
        	deferred.resolve(data);
        });
        return deferred.promise;
    };

    service.createWellTest = function(t){
        var deferred = $q.defer();
        var well_test = {
            'duration_hours': t.duration_hours,
            'volume_h2o_actual': t.volume_h2o_actual,
            'volume_oil_actual': t.volume_oil_actual,
            'volume_gas_actual': t.volume_gas_actual,
            'volume_h2o_projected': t.volume_h2o_projected,
            'volume_oil_projected': t.volume_oil_projected,
            'volume_gas_projected': t.volume_gas_projected,
            'api_gravity_oil': t.api_gravity_oil,
            'spc_gravity_h2o': t.spc_gravity_h2o,
            'created_on': t.created_on
        };
        $http.post('/api/well_tests', well_test).success(function(data){
            deferred.resolve(data);
        });
        return deferred.promise;
    };

    service.updateWellTest = function(t){
        var deferred = $q.defer();
        var well_test = {
            'duration_hours': t.duration_hours,
            'volume_h2o_actual': t.volume_h2o_actual,
            'volume_oil_actual': t.volume_oil_actual,
            'volume_gas_actual': t.volume_gas_actual,
            'volume_h2o_projected': t.volume_h2o_projected,
            'volume_oil_projected': t.volume_oil_projected,
            'volume_gas_projected': t.volume_gas_projected,
            'api_gravity_oil': t.api_gravity_oil,
            'spc_gravity_h2o': t.spc_gravity_h2o,
            'created_on': t.created_on
        };
        $http.put('/api/well_tests/'+ t._id, data=well_test).success(function(data){
            deferred.resolve(data);
        });
        return deferred.promise;
    };

    service.deleteWellTest = function(id){
        var deferred = $q.defer();
        var url = '/api/well_tests/' + id;
        $http.delete(url).success(function(data) {
            deferred.resolve({
                data: data
            });
        });
        return deferred.promise;
    };



    return service;
});
