app.factory('httpRequestFactory', function ($http, $window) {
    
    return {
        getData: function (url) {
            return $http({
                url: url,
                method: "GET"
            })
        },

        getData: function (url, parametros) {
            return $http({
                url: url,
                method: "GET",
                params: parametros
            })
        },

        getDataId: function (url,id) {
            //console.log(id);
            return $http({
                url: url + '/' + id,
                method: "GET",
                cache: false
            })

        },
        
        addData: function (url,dataObj) {
             return $http({
                cache: false,
                url: url,
                method: "POST",
                data: dataObj
            })
        },
        
        deleteData: function (url,id) {
            return $http({
                url: url + '/' + id,
                method: "DELETE"
            })

        },

        updateData: function (url,dataObj,dataObjId) {
            return $http.put(url + '/' + dataObjId, dataObj);
        },

        postData: function (url, dataObj) {
            return $http({
                cache: false,
                url: url,
                method: "POST",
                data: dataObj
            })
        },
        postDataHeader: function (url, dataObj, headersV) {
            return $http.post(url, dataObj, { headers: headersV });
        },
        getDownload: function (url, dataObj) {
            var fd = new FormData();
            if (dataObj!=null)
                fd.append('data', angular.toJson(dataObj));
            return $http.post(url, fd, {
                transformRequest: angular.identity,
                responseType: 'arraybuffer',
                headers: { 'Content-Type': undefined }
            });
        },
        getDataHeaders: function (_url, headersV) {
            return $http({
                method: 'GET', url: _url, headers: headersV
            });
        },
        getDataSync: function (_url) {
            var r = null;
            jQuery.ajax({
                url: _url,
                headers: {
                    'Authorization': '' + $window.sessionStorage.token,
                    'Atk': $window.sessionStorage.CibeAtk
                },
                success: function (result) {
                    r = result;
                },
                async: false
            });
            return r;
        }
    };
});