import { z } from 'zod';
import { globalOptionsZod } from '../../../../Command.js';
import GraphCommand from '../../../base/GraphCommand.js';
import commands from '../../commands.js';
import request from '../../../../request.js';
import { validation } from '../../../../utils/validation.js';
export const options = z.strictObject({
    ...globalOptionsZod.shape,
    id: z.string().alias('i'),
    newName: z.string().optional(),
    description: z.string().optional(),
    isOcrEnabled: z.boolean().optional(),
    isItemVersioningEnabled: z.boolean().optional(),
    itemMajorVersionLimit: z.number()
        .refine(numb => validation.isValidPositiveInteger(numb), {
        error: e => `'${e.input}' is not a valid positive integer.`
    }).optional()
});
class SpeContainerSetCommand extends GraphCommand {
    get name() {
        return commands.CONTAINER_SET;
    }
    get description() {
        return 'Updates a SharePoint Embedded container';
    }
    get schema() {
        return options;
    }
    getRefinedSchema(schema) {
        return schema
            .refine(o => o.newName !== undefined || o.description !== undefined || o.isOcrEnabled !== undefined || o.isItemVersioningEnabled !== undefined || o.itemMajorVersionLimit !== undefined, {
            error: 'Specify at least one of newName, description, isOcrEnabled, isItemVersioningEnabled, or itemMajorVersionLimit.'
        });
    }
    async commandAction(logger, args) {
        if (this.verbose) {
            await logger.logToStderr(`Updating container '${args.options.id}'...`);
        }
        try {
            const data = {};
            if (args.options.newName !== undefined) {
                data.displayName = args.options.newName;
            }
            if (args.options.description !== undefined) {
                data.description = args.options.description;
            }
            const settings = {};
            if (args.options.isOcrEnabled !== undefined) {
                settings.isOcrEnabled = args.options.isOcrEnabled;
            }
            if (args.options.isItemVersioningEnabled !== undefined) {
                settings.isItemVersioningEnabled = args.options.isItemVersioningEnabled;
            }
            if (args.options.itemMajorVersionLimit !== undefined) {
                settings.itemMajorVersionLimit = args.options.itemMajorVersionLimit;
            }
            if (Object.keys(settings).length > 0) {
                data.settings = settings;
            }
            const requestOptions = {
                url: `${this.resource}/v1.0/storage/fileStorage/containers/${args.options.id}`,
                headers: {
                    accept: 'application/json;odata.metadata=none'
                },
                responseType: 'json',
                data
            };
            const container = await request.patch(requestOptions);
            await logger.log(container);
        }
        catch (err) {
            this.handleRejectedODataJsonPromise(err);
        }
    }
}
export default new SpeContainerSetCommand();
//# sourceMappingURL=container-set.js.map