(function () {
    'use strict';

    angular
        .module('setoresApp')
        .factory('serverFactory', serverFactory);

    serverFactory.$inject = ['$http', '__env'];

    function serverFactory($http, __env) {
        function get(action, data) {
            let req = {
                method: 'GET',
                url: __env.baseUrl + '/' + action,
                headers: {
                    'Content-Type': 'application/json; charset=utf-8',
                    'x-api-key': '0ff6134bec254f9ba1f96d15082d20f2'
                },
                data: data ? data : null
            };
            return $http(req);
        }

        function post(action, data) {
            let req = {
                method: 'POST',
                url: __env.baseUrl + '/' + action,
                headers: {
                    'Content-Type': 'application/json; charset=utf-8',
                    'x-api-key': '0ff6134bec254f9ba1f96d15082d20f2'
                },
                data: data
            };
            return $http(req);
        }

        function postFile(action, data) {
            let req = {
                method: 'POST',
                url: __env.baseUrl + '/' + action,
                headers: { 'Content-Type': undefined },
                data: data,
                ransformRequest: angular.identity
            };
            return $http(req);

        }

        return {
            get: get,
            post: post,
            postFile: postFile
        };
    }
})();
