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 GraphCommand from '../../../base/GraphCommand.js';
import commands from '../../commands.js';
export const options = z.strictObject({
    ...globalOptionsZod.shape,
    userId: z.uuid().optional(),
    userName: z.string().optional(),
    ids: z.string().refine(ids => !ids.split(',').some(e => !validation.isValidGuid(e)), {
        error: e => `'${e.input}' contains one or more invalid GUIDs.`
    })
});
class EntraUserLicenseAddCommand extends GraphCommand {
    get name() {
        return commands.USER_LICENSE_ADD;
    }
    get description() {
        return 'Assigns a license to a user';
    }
    get schema() {
        return options;
    }
    getRefinedSchema(schema) {
        return schema
            .refine(options => [options.userId, options.userName].filter(o => o !== undefined).length === 1, {
            error: `Specify either 'userId' or 'userName'.`,
            params: {
                customCode: 'optionSet',
                options: ['userId', 'userName']
            }
        });
    }
    async commandAction(logger, args) {
        const addLicenses = args.options.ids.split(',').map(x => { return { "disabledPlans": [], "skuId": x }; });
        const requestBody = { "addLicenses": addLicenses, "removeLicenses": [] };
        const requestOptions = {
            url: `${this.resource}/v1.0/users/${formatting.encodeQueryParameter(args.options.userId ?? args.options.userName)}/assignLicense`,
            headers: {
                accept: 'application/json;odata.metadata=none'
            },
            data: requestBody,
            responseType: 'json'
        };
        try {
            const response = await request.post(requestOptions);
            await logger.log(response);
        }
        catch (err) {
            this.handleRejectedODataJsonPromise(err);
        }
    }
}
export default new EntraUserLicenseAddCommand();
//# sourceMappingURL=user-license-add.js.map