import { z } from 'zod';
import { cli } from '../../../../cli/cli.js';
import { globalOptionsZod } from '../../../../Command.js';
import request from '../../../../request.js';
import { formatting } from '../../../../utils/formatting.js';
import PowerAutomateCommand from '../../../base/PowerAutomateCommand.js';
import commands from '../../commands.js';
export const options = z.strictObject({
    ...globalOptionsZod.shape,
    name: z.string().alias('n'),
    flowName: z.uuid(),
    environmentName: z.string().alias('e'),
    force: z.boolean().optional().alias('f')
});
class FlowRunCancelCommand extends PowerAutomateCommand {
    get name() {
        return commands.RUN_CANCEL;
    }
    get description() {
        return 'Cancels a specific run of the specified Microsoft Flow';
    }
    get schema() {
        return options;
    }
    async commandAction(logger, args) {
        if (this.verbose) {
            await logger.log(`Cancelling run ${args.options.name} of Microsoft Flow ${args.options.flowName}...`);
        }
        const cancelFlow = async () => {
            const requestOptions = {
                url: `${PowerAutomateCommand.resource}/providers/Microsoft.ProcessSimple/environments/${formatting.encodeQueryParameter(args.options.environmentName)}/flows/${formatting.encodeQueryParameter(args.options.flowName)}/runs/${formatting.encodeQueryParameter(args.options.name)}/cancel?api-version=2016-11-01`,
                headers: {
                    accept: 'application/json'
                },
                responseType: 'json'
            };
            try {
                await request.post(requestOptions);
            }
            catch (err) {
                this.handleRejectedODataJsonPromise(err);
            }
        };
        if (args.options.force) {
            await cancelFlow();
        }
        else {
            const result = await cli.promptForConfirmation({ message: `Are you sure you want to cancel the flow run ${args.options.name}?` });
            if (result) {
                await cancelFlow();
            }
        }
    }
}
export default new FlowRunCancelCommand();
//# sourceMappingURL=run-cancel.js.map