import { z } from 'zod';
import { cli } from '../../../../cli/cli.js';
import { globalOptionsZod } from '../../../../Command.js';
import { formatting } from '../../../../utils/formatting.js';
import { odata } from '../../../../utils/odata.js';
import PowerAutomateCommand from '../../../base/PowerAutomateCommand.js';
import commands from '../../commands.js';
export const options = z.strictObject({
    ...globalOptionsZod.shape,
    flowName: z.uuid(),
    environmentName: z.string().alias('e'),
    asAdmin: z.boolean().optional()
});
class FlowOwnerListCommand extends PowerAutomateCommand {
    get name() {
        return commands.OWNER_LIST;
    }
    get description() {
        return 'Lists all owners of a Power Automate flow';
    }
    defaultProperties() {
        return ['roleName', 'id', 'type'];
    }
    get schema() {
        return options;
    }
    async commandAction(logger, args) {
        try {
            if (this.verbose) {
                await logger.logToStderr(`Listing owners for flow ${args.options.flowName} in environment ${args.options.environmentName}`);
            }
            const response = await odata.getAllItems(`${PowerAutomateCommand.resource}/providers/Microsoft.ProcessSimple/${args.options.asAdmin ? 'scopes/admin/' : ''}environments/${formatting.encodeQueryParameter(args.options.environmentName)}/flows/${formatting.encodeQueryParameter(args.options.flowName)}/permissions?api-version=2016-11-01`);
            if (!cli.shouldTrimOutput(args.options.output)) {
                await logger.log(response);
            }
            else {
                //converted to text friendly output
                await logger.log(response.map(res => ({
                    roleName: res.properties.roleName,
                    id: res.properties.principal.id,
                    type: res.properties.principal.type
                })));
            }
        }
        catch (err) {
            this.handleRejectedODataJsonPromise(err);
        }
    }
}
export default new FlowOwnerListCommand();
//# sourceMappingURL=owner-list.js.map