// SPDX-License-Identifier: Apache-2.0
import { Flags as flags } from '../commands/flags.js';
import { NamespaceName } from '../types/namespace/namespace-name.js';
import { input as inputPrompt } from '@inquirer/prompts';
import { SoloError } from './errors/solo-error.js';
export async function resolveNamespaceFromDeployment(localConfig, configManager, task) {
    const deploymentName = await promptTheUserForDeployment(configManager, task);
    return NamespaceName.of(localConfig.configuration.deploymentByName(deploymentName).namespace);
}
export async function promptTheUserForDeployment(configManager, task) {
    if (configManager.getFlag(flags.deployment)) {
        return configManager.getFlag(flags.deployment);
    }
    if (task) {
        await configManager.executePrompt(task, [flags.deployment]);
    }
    else {
        const isQuiet = configManager.getFlag(flags.quiet);
        const isForced = configManager.getFlag(flags.force);
        // if the quiet or forced flag is passed don't prompt the user
        if (isQuiet === true || isForced === true) {
            throw new SoloError('deployment is required');
        }
        const answer = await inputPrompt({
            message: 'Enter the name of the deployment:',
            validate: (value) => !!value,
        });
        configManager.setFlag(flags.deployment, answer);
    }
    const deploymentName = configManager.getFlag(flags.deployment);
    if (!deploymentName) {
        throw new SoloError('deployment is required');
    }
    return deploymentName;
}
//# sourceMappingURL=resolvers.js.map