import { z } from 'zod';
import { globalOptionsZod } from '../../../../Command.js';
import { cli } from '../../../../cli/cli.js';
import request from '../../../../request.js';
import { formatting } from '../../../../utils/formatting.js';
import GraphCommand from '../../../base/GraphCommand.js';
import commands from '../../commands.js';
export const options = globalOptionsZod
    .extend({
    grantId: z.string().alias('i'),
    force: z.boolean().optional().alias('f')
}).strict();
class EntraOAuth2GrantRemoveCommand extends GraphCommand {
    get name() {
        return commands.OAUTH2GRANT_REMOVE;
    }
    get description() {
        return 'Removes specified service principal OAuth2 permissions';
    }
    get schema() {
        return options;
    }
    async commandAction(logger, args) {
        const removeOauth2Grant = async () => {
            if (this.verbose) {
                await logger.logToStderr(`Removing OAuth2 permissions...`);
            }
            try {
                const requestOptions = {
                    url: `${this.resource}/v1.0/oauth2PermissionGrants/${formatting.encodeQueryParameter(args.options.grantId)}`,
                    headers: {
                        'accept': 'application/json;odata.metadata=none'
                    },
                    responseType: 'json'
                };
                await request.delete(requestOptions);
            }
            catch (err) {
                this.handleRejectedODataJsonPromise(err);
            }
        };
        if (args.options.force) {
            await removeOauth2Grant();
        }
        else {
            const result = await cli.promptForConfirmation({ message: `Are you sure you want to remove the OAuth2 permissions for ${args.options.grantId}?` });
            if (result) {
                await removeOauth2Grant();
            }
        }
    }
}
export default new EntraOAuth2GrantRemoveCommand();
//# sourceMappingURL=oauth2grant-remove.js.map