import { z } from 'zod';
import { globalOptionsZod } from '../../../../Command.js';
import commands from '../../commands.js';
import request from '../../../../request.js';
import { validation } from '../../../../utils/validation.js';
import { cli } from '../../../../cli/cli.js';
import GraphCommand from '../../../base/GraphCommand.js';
export const options = z.strictObject({
    ...globalOptionsZod.shape,
    id: z.uuid().optional(),
    userName: z.string().refine(name => validation.isValidUserPrincipalName(name), {
        error: e => `'${e.input}' is not a valid user principal name (UPN).`
    }).optional(),
    force: z.boolean().optional().alias('f')
});
class EntraUserRemoveCommand extends GraphCommand {
    get name() {
        return commands.USER_REMOVE;
    }
    get description() {
        return 'Removes a specific user';
    }
    get schema() {
        return options;
    }
    getRefinedSchema(schema) {
        return schema
            .refine(options => [options.id, options.userName].filter(o => o !== undefined).length === 1, {
            error: `Specify either 'id' or 'userName'.`,
            params: {
                customCode: 'optionSet',
                options: ['id', 'userName']
            }
        });
    }
    async commandAction(logger, args) {
        if (this.verbose) {
            await logger.logToStderr(`Removing user '${args.options.id || args.options.userName}'...`);
        }
        if (args.options.force) {
            await this.deleteUser(args);
        }
        else {
            const result = await cli.promptForConfirmation({ message: `Are you sure you want to remove user '${args.options.id || args.options.userName}'?` });
            if (result) {
                await this.deleteUser(args);
            }
        }
    }
    async deleteUser(args) {
        try {
            const requestOptions = {
                url: `${this.resource}/v1.0/users/${args.options.id || args.options.userName}`,
                headers: {
                    accept: 'application/json;odata.metadata=none'
                },
                responseType: 'json'
            };
            await request.delete(requestOptions);
        }
        catch (err) {
            this.handleRejectedODataJsonPromise(err);
        }
    }
}
export default new EntraUserRemoveCommand();
//# sourceMappingURL=user-remove.js.map