import { z } from 'zod';
import { globalOptionsZod } from '../../../../Command.js';
import request from '../../../../request.js';
import { formatting } from '../../../../utils/formatting.js';
import { validation } from '../../../../utils/validation.js';
import AnonymousCommand from '../../../base/AnonymousCommand.js';
import commands from '../../commands.js';
export const options = z.strictObject({
    ...globalOptionsZod.shape,
    userName: z.string().refine(name => validation.isValidUserPrincipalName(name), {
        error: 'Specify valid userName.'
    }).alias('n'),
    apiKey: z.string(),
    domain: z.string().optional()
});
class EntraUserHibpCommand extends AnonymousCommand {
    get name() {
        return commands.USER_HIBP;
    }
    get description() {
        return 'Allows you to retrieve all accounts that have been pwned with the specified username';
    }
    get schema() {
        return options;
    }
    async commandAction(logger, args) {
        try {
            const requestOptions = {
                url: `https://haveibeenpwned.com/api/v3/breachedaccount/${formatting.encodeQueryParameter(args.options.userName)}${(args.options.domain ? `?domain=${formatting.encodeQueryParameter(args.options.domain)}` : '')}`,
                headers: {
                    'accept': 'application/json',
                    'hibp-api-key': args.options.apiKey,
                    'x-anonymous': true
                },
                responseType: 'json'
            };
            const res = await request.get(requestOptions);
            await logger.log(res);
        }
        catch (err) {
            if ((err && err.response !== undefined && err.response.status === 404) && (this.debug || this.verbose)) {
                await logger.log('No pwnage found');
                return;
            }
            this.handleRejectedODataJsonPromise(err);
        }
    }
}
export default new EntraUserHibpCommand();
//# sourceMappingURL=user-hibp.js.map