import { isDefined } from '@takeshape/util';
import isEmpty from 'lodash/isEmpty.js';
import uniq from 'lodash/uniq.js';
/**
 * Get a service config from a project schema.
 */
export function getStoredServiceConfig(projectSchema, serviceKey) {
    return projectSchema.services?.[serviceKey];
}
/**
 * Get a `Map` keyed with all the service namespaces.
 *
 * @param context A partial project schema
 *
 * @returns A `Map` with namespaces as keys, and service keys as values.
 */
export function getServiceNamespaces(context) {
    const namespaces = new Map();
    const { services } = context;
    if (services) {
        for (const serviceKey of Object.keys(services)) {
            const namespace = services[serviceKey]?.namespace;
            if (namespace) {
                namespaces.set(namespace, serviceKey);
            }
        }
    }
    return namespaces;
}
export function isMissingAuth(service) {
    return service.authenticationType !== 'none' && isEmpty(service.authentication);
}
export function getResolverServices(resolver) {
    const resolverArray = 'compose' in resolver ? resolver.compose : [resolver];
    return uniq(resolverArray.map((resolver) => ('service' in resolver ? resolver.service : undefined)).filter(isDefined));
}
