import { z } from 'zod';
import { globalOptionsZod } from '../../../../Command.js';
import { entraGroup } from '../../../../utils/entraGroup.js';
import { planner } from '../../../../utils/planner.js';
import { validation } from '../../../../utils/validation.js';
import GraphCommand from '../../../base/GraphCommand.js';
import commands from '../../commands.js';
export const options = z.strictObject({
    ...globalOptionsZod.shape,
    ownerGroupId: z.string()
        .refine(val => validation.isValidGuid(val), {
        message: 'The value is not a valid GUID.'
    })
        .optional(),
    ownerGroupName: z.string().optional(),
    rosterId: z.string().optional()
});
class PlannerPlanListCommand extends GraphCommand {
    get name() {
        return commands.PLAN_LIST;
    }
    get description() {
        return 'Returns a list of plans associated with a specified group or roster';
    }
    defaultProperties() {
        return ['id', 'title', 'createdDateTime', 'owner'];
    }
    get schema() {
        return options;
    }
    getRefinedSchema(schema) {
        return schema
            .refine(opts => [opts.ownerGroupId, opts.ownerGroupName, opts.rosterId].filter(x => x !== undefined).length === 1, {
            message: `Specify exactly one of the following options: 'ownerGroupId', 'ownerGroupName' or 'rosterId'.`,
            params: {
                customCode: 'optionSet',
                options: ['ownerGroupId', 'ownerGroupName', 'rosterId']
            }
        });
    }
    async commandAction(logger, args) {
        try {
            let plannerPlans = [];
            if (args.options.ownerGroupId || args.options.ownerGroupName) {
                const groupId = await this.getGroupId(args);
                plannerPlans = await planner.getPlansByGroupId(groupId);
            }
            else {
                const plan = await planner.getPlanByRosterId(args.options.rosterId);
                plannerPlans.push(plan);
            }
            await logger.log(plannerPlans);
        }
        catch (err) {
            this.handleRejectedODataJsonPromise(err);
        }
    }
    async getGroupId(args) {
        if (args.options.ownerGroupId) {
            return args.options.ownerGroupId;
        }
        return entraGroup.getGroupIdByDisplayName(args.options.ownerGroupName);
    }
}
export default new PlannerPlanListCommand();
//# sourceMappingURL=plan-list.js.map