"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var rxjs_1 = require("rxjs");
var singleton = Symbol();
var singletonEnforcer = Symbol();
var HttpService = /** @class */ (function () {
    function HttpService(enforcer) {
        this.optionDefaults = {
            cache: 'no-cache',
            credentials: 'same-origin',
            headers: {},
            mode: 'same-origin',
            method: 'GET',
        };
        if (enforcer !== singletonEnforcer) {
            throw new Error('Cannot construct singleton');
        }
        this._type = 'HttpService';
    }
    HttpService.prototype.get = function (url, options) {
        if (options === void 0) { options = this.optionDefaults; }
        return rxjs_1.Observable.create(function (observer) {
            fetch(url, options)
                .then(function (response) { return response.json(); }) // or text() or blob() etc.
                .then(function (data) {
                observer.next(data);
                observer.complete();
            })
                .catch(function (err) {
                console.error('http.get error:', err);
                observer.error(err);
            });
        });
        // data$.subscribe(data => /*do something with data*/);
    };
    HttpService.prototype.put = function (url, object, options) {
    };
    HttpService.prototype.post = function (url, object, options) {
    };
    HttpService.prototype.delete = function (url, object, options) {
    };
    Object.defineProperty(HttpService, "instance", {
        get: function () {
            if (!this[singleton]) {
                this[singleton] = new HttpService(singletonEnforcer);
            }
            return this[singleton];
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(HttpService.prototype, "type", {
        get: function () {
            return this._type;
        },
        set: function (value) {
            this._type = value;
        },
        enumerable: true,
        configurable: true
    });
    return HttpService;
}());
exports.HttpService = HttpService;
//# sourceMappingURL=http-service.js.map