"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getLatestAuthoredTestsOutputSchema = void 0;
const zod_1 = require("zod");
const testUtils_1 = require("../utils/testUtils");
const mcpMablTool_1 = require("./mcpMablTool");
const cliConfigProvider_1 = require("@mablhq-internal/runtime/providers/cliConfigProvider");
const common_1 = require("../utils/common");
exports.getLatestAuthoredTestsOutputSchema = zod_1.z.object({
    latestAuthoredTests: zod_1.z
        .array(testUtils_1.testOutputSchema)
        .describe('Array of latest tests authored by the current user'),
});
const getLatestAuthoredTests = (0, mcpMablTool_1.defineTool)({
    schema: {
        name: 'get_latest_authored_tests',
        title: 'Get latest authored tests',
        description: 'Get latest tests created by the current user. Example: What mabl tests have I created recently?',
        inputSchema: zod_1.z.object({
            limit: zod_1.z
                .number()
                .min(1)
                .max(100)
                .optional()
                .describe('Maximum number of tests to return (default: 10)'),
        }),
        type: 'readOnly',
        outputSchema: exports.getLatestAuthoredTestsOutputSchema,
    },
    handle: async (args, context) => {
        const { mablApiClient, workspaceId } = context.getCurrentContext();
        const limit = args.limit || 10;
        const userInfo = await cliConfigProvider_1.CliConfigProvider.getCliConfig();
        if (!userInfo.userId) {
            return (0, common_1.stringToToolResult)('Unable to determine current user information.', true);
        }
        const authoredTestsResponse = await mablApiClient.getJourneys({
            author_id: userInfo.userId,
            organization_id: workspaceId,
            limit,
        });
        const latestAuthoredTests = authoredTestsResponse.map((test) => (0, testUtils_1.normalizeTest)(test));
        return {
            content: [
                {
                    type: 'text',
                    text: (0, common_1.jsonPrettyPrint)({ latestAuthoredTests }),
                },
            ],
            structuredContent: { latestAuthoredTests },
        };
    },
});
exports.default = [getLatestAuthoredTests];
