import { z } from 'zod';
import { globalOptionsZod } from '../../../../Command.js';
import request from '../../../../request.js';
import GraphCommand from '../../../base/GraphCommand.js';
import commands from '../../commands.js';
export const options = z.looseObject({
    ...globalOptionsZod.shape,
    id: z.uuid().alias('i')
});
class EntraGroupSettingSetCommand extends GraphCommand {
    get name() {
        return commands.GROUPSETTING_SET;
    }
    get description() {
        return 'Updates the particular group setting';
    }
    allowUnknownOptions() {
        return true;
    }
    get schema() {
        return options;
    }
    async commandAction(logger, args) {
        if (this.verbose) {
            await logger.logToStderr(`Retrieving group setting with id '${args.options.id}'...`);
        }
        try {
            let requestOptions = {
                url: `${this.resource}/v1.0/groupSettings/${args.options.id}`,
                headers: {
                    accept: 'application/json;odata.metadata=none'
                },
                responseType: 'json'
            };
            const groupSetting = await request.get(requestOptions);
            requestOptions = {
                url: `${this.resource}/v1.0/groupSettings/${args.options.id}`,
                headers: {
                    accept: 'application/json;odata.metadata=none',
                    'content-type': 'application/json'
                },
                data: {
                    displayName: groupSetting.displayName,
                    templateId: groupSetting.templateId,
                    values: this.getGroupSettingValues(args.options, groupSetting)
                },
                responseType: 'json'
            };
            await request.patch(requestOptions);
        }
        catch (err) {
            this.handleRejectedODataJsonPromise(err);
        }
    }
    getGroupSettingValues(options, groupSetting) {
        const values = [];
        const excludeOptions = [
            'id',
            'debug',
            'verbose',
            'output'
        ];
        Object.keys(options).forEach(key => {
            if (excludeOptions.indexOf(key) === -1) {
                values.push({
                    name: key,
                    value: options[key]
                });
            }
        });
        groupSetting.values.forEach(v => {
            if (!values.find(e => e.name === v.name)) {
                values.push({
                    name: v.name,
                    value: v.value
                });
            }
        });
        return values;
    }
}
export default new EntraGroupSettingSetCommand();
//# sourceMappingURL=groupsetting-set.js.map