/*!
 * Copyright (c) 2026 Vertex Software LLC. All rights reserved.
 */
import { Objects } from "@vertexvis/utils";
import { Animation, Events, Flags, Interactions } from "./types";
const config = {
    network: {
        apiHost: 'https://platform.platprod.vertexvis.io',
        renderingHost: 'wss://stream.platprod.vertexvis.io',
        sceneTreeHost: 'https://scene-trees.platprod.vertexvis.io',
        sceneViewHost: 'https://scenes.platprod.vertexvis.io',
    },
    flags: Flags.defaultFlags,
    events: Events.defaultEventConfig,
    animation: Animation.defaultAnimationConfig,
    interactions: Interactions.defaultInteractionConfig,
    EXPERIMENTAL_frameDelivery: {},
    EXPERIMENTAL_adaptiveRendering: {},
    EXPERIMENTAL_qualityOfService: {},
    EXPERIMENTAL_annotationPollingIntervalInMs: undefined,
};
const platdevConfig = {
    ...config,
    network: {
        apiHost: 'https://platform.platdev.vertexvis.io',
        renderingHost: 'wss://stream.platdev.vertexvis.io',
        sceneTreeHost: 'https://scene-trees.platdev.vertexvis.io',
        sceneViewHost: 'https://scenes.platdev.vertexvis.io',
    },
};
const platstagingConfig = {
    ...config,
    network: {
        apiHost: 'https://platform.platstaging.vertexvis.io',
        renderingHost: 'wss://stream.platstaging.vertexvis.io',
        sceneTreeHost: 'https://scene-trees.platstaging.vertexvis.io',
        sceneViewHost: 'https://scenes.platstaging.vertexvis.io',
    },
};
function getEnvironmentConfig(environment) {
    switch (environment) {
        case 'platdev':
            return platdevConfig;
        case 'platstaging':
            return platstagingConfig;
        default:
            return config;
    }
}
export function parseAndValidateConfig(environment = 'platprod', config) {
    const parsed = parseConfig(environment, config);
    return validateConfig(sanitizeConfig(parsed));
}
export function parseConfig(environment = 'platprod', config) {
    if (typeof config === 'string') {
        config = JSON.parse(config);
    }
    const envConfig = getEnvironmentConfig(environment);
    if (config == null) {
        return envConfig;
    }
    else {
        return Objects.defaults({ ...config }, envConfig);
    }
}
export function sanitizeConfig(config) {
    const sanitizedApiHost = config.network.apiHost.trim();
    const sanitizedRenderingHost = config.network.renderingHost.trim();
    const sanitizedSceneTreeHost = config.network.sceneTreeHost.trim();
    const sanitizedSceneViewHost = config.network.sceneViewHost.trim();
    return {
        ...config,
        network: {
            ...config.network,
            apiHost: sanitizedApiHost,
            renderingHost: sanitizedRenderingHost,
            sceneTreeHost: sanitizedSceneTreeHost,
            sceneViewHost: sanitizedSceneViewHost,
        },
    };
}
export function validateConfig(config) {
    validateUrlScheme(config.network, 'apiHost', 'https://');
    validateUrlScheme(config.network, 'renderingHost', 'wss://');
    validateUrlScheme(config.network, 'sceneTreeHost', 'https://');
    validateUrlScheme(config.network, 'sceneViewHost', 'https://');
    return config;
}
function validateUrlScheme(networkConfig, field, expectedScheme) {
    if (!networkConfig[field].startsWith(expectedScheme)) {
        throw new Error(`Invalid ${field} "${networkConfig[field]}" specified. The URL must start with the ${expectedScheme} scheme.`);
    }
}
//# sourceMappingURL=config.js.map
