"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const zod_1 = require("zod");
const mcpMablTool_1 = require("./mcpMablTool");
const common_1 = require("../utils/common");
const getPlansOutputSchema = zod_1.z.object({
    plans: zod_1.z.array(zod_1.z.object({
        id: zod_1.z.string(),
        name: zod_1.z.string(),
        description: zod_1.z.string().optional(),
        enabled: zod_1.z.boolean().optional(),
        plan_type: zod_1.z.string().optional(),
        tags: zod_1.z.array(zod_1.z.string()).optional(),
        labels: zod_1.z.array(zod_1.z.string()).optional(),
        application_id: zod_1.z.string().optional(),
        created_time: zod_1.z.number().optional(),
        last_updated_time: zod_1.z.number().optional(),
        web_url: zod_1.z.string().optional(),
        api_url: zod_1.z.string().optional(),
    })),
});
const getPlans = (0, mcpMablTool_1.defineTool)({
    schema: {
        name: 'get_plans',
        title: 'Get all mabl plans',
        description: 'Get all mabl plans. Example: Get my mabl plans',
        inputSchema: zod_1.z.object({}),
        type: 'readOnly',
        outputSchema: getPlansOutputSchema,
    },
    handle: async (_, context) => {
        const { mablApiClient, workspaceId } = context.getCurrentContext();
        const limit = 1_000;
        const plans = await mablApiClient.getPlans({
            organization_id: workspaceId,
            limit,
        });
        const plansArray = plans.map((plan) => ({
            id: plan.id ?? '',
            name: plan.name ?? '',
            description: plan.description,
            enabled: plan.enabled,
            plan_type: plan.plan_type,
            tags: plan.tags ? plan.tags.map((tag) => tag.name) : [],
            labels: plan.labels ? plan.labels.map((label) => label.name) : [],
            application_id: undefined,
            created_time: plan.created_time,
            last_updated_time: plan.last_updated_time,
            web_url: plan.web_url,
            api_url: plan.api_url,
        }));
        return {
            content: [
                {
                    type: 'text',
                    text: (0, common_1.jsonPrettyPrint)(plansArray),
                },
            ],
            structuredContent: { plans: plansArray },
        };
    },
});
exports.default = [getPlans];
