import { updateApplicationProperty } from '../srv/update-application-property.js';
import { getApplicationOrVersionNamesCompletion } from './common/completions.js';

export const getMetadata = () => ({
    name: 'start',
    desc: 'Start deployed application',
    usage: 'afctl start APPLICATION',
    options: {
        application: {
            keys: [],
            type: 'string',
            mandatory: true,
            multiple: false,
            helpLiteral: 'APPLICATION',
            helpText: 'Name of the deployed application',
            index: 0
        }
    }
});

export const getCompletion = getApplicationOrVersionNamesCompletion({versionCompletion: false});

export const run = async ({ args, config, console, fetch }) => {
    const profile = config?.profiles?.[config?.active_profile];
    console.debug(`Starting application '${args.application}'`);
    await updateApplicationProperty({
        console, profile, fetch,
        application: args.application,
        property: {
            name: 'state',
            value: 'started'
        }
    });
};
