(function () {
    'use strict';

    angular
        .module('controleApp')
        .factory('Server', Server);

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

    function Server($http, __env) {
        function get(action, data, successCallback, errorCallback) {
            let baseUrl = window.location.origin + urlGlobal + 'Controle';
            let req = {
                method: 'GET',
                url: baseUrl + '/' + action,
                headers: {
                    'Content-Type': 'application/json; charset=utf-8',
                },
                data: data ? data : null
            };
            $http(req).then(function (data) {
                successCallback(data);
            }, function (error) {
                if (error)
                    errorCallback(error);
            });
        }
        function getArea(action, data, successCallback, errorCallback) {
            let baseUrl = window.location.origin + urlGlobal;
            let req = {
                method: 'GET',
                url: baseUrl + '/' + action,
                headers: {
                    'Content-Type': 'application/json; charset=utf-8',
                },
                data: data ? data : null
            };
            $http(req).then(function (data) {
                successCallback(data);
            }, function (error) {
                if (error)
                    errorCallback(error);
            });
        }
        function post(action, data, successCallback, errorCallback) {
            let baseUrl = window.location.origin + urlGlobal + 'Controle';
            let req = {
                method: 'POST',
                url: baseUrl + '/' + action,
                headers: {
                    'Content-Type': 'application/json; charset=utf-8'
                },
                data: data
            };
            $http(req).then(function (data) {
                successCallback(data);
            }, function (error) {
                if (error)
                    errorCallback(error);
            });
        }
        function postArea(action, data, successCallback, errorCallback) {
            let baseUrl = window.location.origin + urlGlobal;
            let req = {
                method: 'POST',
                url: baseUrl + action,
                headers: {
                    'Content-Type': 'application/json; charset=utf-8'
                },
                data: data
            };
            $http(req).then(function (data) {
                successCallback(data);
            }, function (error) {
                if (error)
                    errorCallback(error);
            });
        }

        return {
            get: get,
            post: post,
            getArea: getArea,
            postArea: postArea
        };
    }
})();
