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.strictObject({
    ...globalOptionsZod.shape,
    externalConnectionId: z.string().alias('c'),
    baseUrls: z.string(),
    urlPattern: z.string(),
    itemId: z.string().alias('i'),
    priority: z.number().alias('p')
});
class ExternalConnectionUrlToItemResolverAddCommand extends GraphCommand {
    get name() {
        return commands.CONNECTION_URLTOITEMRESOLVER_ADD;
    }
    get description() {
        return 'Adds a URL to item resolver to an external connection';
    }
    get schema() {
        return options;
    }
    async commandAction(logger, args) {
        const baseUrls = args.options.baseUrls.split(',').map(b => b.trim());
        const itemIdResolver = {
            itemId: args.options.itemId,
            priority: args.options.priority,
            urlMatchInfo: {
                baseUrls: baseUrls,
                urlPattern: args.options.urlPattern
            }
        };
        // not a part of the type definition, but required by the API
        itemIdResolver['@odata.type'] = '#microsoft.graph.externalConnectors.itemIdResolver';
        const requestOptions = {
            url: `${this.resource}/v1.0/external/connections/${args.options.externalConnectionId}`,
            headers: {
                accept: 'application/json;odata.metadata=none',
                'content-type': 'application/json'
            },
            responseType: 'json',
            data: {
                activitySettings: {
                    urlToItemResolvers: [itemIdResolver]
                }
            }
        };
        try {
            await request.patch(requestOptions);
        }
        catch (err) {
            this.handleRejectedODataJsonPromise(err);
        }
    }
}
export default new ExternalConnectionUrlToItemResolverAddCommand();
//# sourceMappingURL=connection-urltoitemresolver-add.js.map