import { z } from 'zod';
import { globalOptionsZod } from '../../../../Command.js';
import request from '../../../../request.js';
import { formatting } from '../../../../utils/formatting.js';
import GraphCommand from '../../../base/GraphCommand.js';
import commands from '../../commands.js';
export const options = z.strictObject({
    ...globalOptionsZod.shape,
    id: z.string().optional().alias('i'),
    name: z.string().optional().alias('n')
});
class ExternalConnectionGetCommand extends GraphCommand {
    get name() {
        return commands.CONNECTION_GET;
    }
    get description() {
        return 'Allows the administrator to get a specific external connection';
    }
    alias() {
        return [commands.EXTERNALCONNECTION_GET];
    }
    get schema() {
        return options;
    }
    getRefinedSchema(schema) {
        return schema
            .refine(options => [options.id, options.name].filter(x => x !== undefined).length === 1, {
            message: `Specify either 'id' or 'name', but not both.`,
            params: {
                customCode: 'optionSet',
                options: ['id', 'name']
            }
        });
    }
    async commandAction(logger, args) {
        let url = `${this.resource}/v1.0/external/connections`;
        if (args.options.id) {
            url += `/${formatting.encodeQueryParameter(args.options.id)}`;
        }
        else {
            url += `?$filter=name eq '${formatting.encodeQueryParameter(args.options.name)}'`;
        }
        const requestOptions = {
            url: url,
            headers: {
                accept: 'application/json;odata.metadata=none'
            },
            responseType: 'json'
        };
        try {
            let res = await request.get(requestOptions);
            if (args.options.name) {
                if (res.value.length === 0) {
                    throw `External connection with name '${args.options.name}' not found`;
                }
                res = res.value[0];
            }
            await logger.log(res);
        }
        catch (err) {
            this.handleRejectedODataJsonPromise(err);
        }
    }
}
export default new ExternalConnectionGetCommand();
//# sourceMappingURL=connection-get.js.map