import { z } from 'zod';
import { globalOptionsZod } from '../../../../Command.js';
import { odata } from '../../../../utils/odata.js';
import GraphCommand from '../../../base/GraphCommand.js';
import commands from '../../commands.js';
export const options = z.strictObject({
    ...globalOptionsZod.shape,
    displayName: z.string().optional().alias('n'),
    tag: z.string().optional()
});
class EntraEnterpriseAppListCommand extends GraphCommand {
    get name() {
        return commands.ENTERPRISEAPP_LIST;
    }
    defaultProperties() {
        return ['appId', 'displayName', 'tag'];
    }
    get description() {
        return 'Lists the enterprise applications (or service principals) in Entra ID';
    }
    alias() {
        return [commands.SP_LIST];
    }
    get schema() {
        return options;
    }
    async commandAction(logger, args) {
        if (this.verbose) {
            await logger.logToStderr(`Retrieving enterprise application information...`);
        }
        try {
            let requestUrl = `${this.resource}/v1.0/servicePrincipals`;
            const filter = [];
            if (args.options.tag) {
                filter.push(`(tags/any(t:t eq '${args.options.tag}'))`);
            }
            if (args.options.displayName) {
                filter.push(`(displayName eq '${args.options.displayName}')`);
            }
            if (filter.length > 0) {
                requestUrl += `?$filter=${filter.join(' and ')}`;
            }
            const res = await odata.getAllItems(requestUrl);
            await logger.log(res);
        }
        catch (err) {
            this.handleRejectedODataJsonPromise(err);
        }
    }
}
export default new EntraEnterpriseAppListCommand();
//# sourceMappingURL=enterpriseapp-list.js.map