"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Config = exports.Network = exports.ConfigService = exports.ConfigServicePath = void 0;
exports.ConfigServicePath = '/services/config-service';
exports.ConfigService = Symbol('ConfigService');
var Network;
(function (Network) {
    function Default() {
        return {
            protocol: 'http',
            hostname: '',
            port: '',
            username: '',
            password: ''
        };
    }
    Network.Default = Default;
    function parse(raw) {
        if (!raw) {
            return 'none';
        }
        try {
            // Patter: PROTOCOL://USER:PASS@HOSTNAME:PORT/
            var _a = new URL(raw), protocol = _a.protocol, hostname = _a.hostname, password = _a.password, username = _a.username, port = _a.port;
            return {
                protocol: protocol,
                hostname: hostname,
                password: password,
                username: username,
                port: port
            };
        }
        catch (_b) {
            return 'none';
        }
    }
    Network.parse = parse;
    ;
    function stringify(network) {
        if (network === 'none') {
            return undefined;
        }
        var protocol = network.protocol, hostname = network.hostname, password = network.password, username = network.username, port = network.port;
        try {
            var defaultUrl = new URL((protocol ? protocol : 'http') + "://" + (hostname ? hostname : '_'));
            return Object.assign(defaultUrl, { protocol: protocol, hostname: hostname, password: password, username: username, port: port }).toString();
        }
        catch (_a) {
            return undefined;
        }
    }
    Network.stringify = stringify;
    function sameAs(left, right) {
        if (left === 'none') {
            return right === 'none';
        }
        if (right === 'none') {
            return false;
        }
        return left.hostname === right.hostname
            && left.password === right.password
            && left.protocol === right.protocol
            && left.username === right.username;
    }
    Network.sameAs = sameAs;
    ;
})(Network = exports.Network || (exports.Network = {}));
var Config;
(function (Config) {
    function sameAs(left, right) {
        var leftUrls = left.additionalUrls.sort();
        var rightUrls = right.additionalUrls.sort();
        if (leftUrls.length !== rightUrls.length) {
            return false;
        }
        for (var i = 0; i < leftUrls.length; i++) {
            if (leftUrls[i] !== rightUrls[i]) {
                return false;
            }
        }
        return left.dataDirUri === right.dataDirUri
            && left.downloadsDirUri === right.downloadsDirUri
            && left.sketchDirUri === right.sketchDirUri
            && Network.sameAs(left.network, right.network);
    }
    Config.sameAs = sameAs;
})(Config = exports.Config || (exports.Config = {}));
//# sourceMappingURL=config-service.js.map