import { TestType } from "../../types/TestTypes.js";
import { TestGenerationService, } from "../../services/TestGenerationService.js";
import { AnalyticsService } from "../../services/AnalyticsService.js";
import { loadTestSchema } from "./loadTestSchema.js";
// Re-export for backwards compatibility
export { loadTestSchema, numericString } from "./loadTestSchema.js";
export class LoadTestService extends TestGenerationService {
    getTestType() {
        return TestType.LOAD;
    }
    buildGenerationOptions(params) {
        return {
            ...super.buildBaseGenerationOptions(params),
            loadCount: params.loadCount,
            loadDuration: params.loadDuration,
            loadNumThreads: params.loadNumThreads,
            loadRampupDuration: params.loadRampupDuration,
            loadRampupInterval: params.loadRampupInterval,
            loadTargetRPS: params.loadTargetRPS,
        };
    }
    async handleApiAnalysis(params) {
        return null;
    }
}
const TOOL_NAME = "skyramp_load_test_generation";
export function registerLoadTestTool(server) {
    server.registerTool(TOOL_NAME, {
        description: `Generate a load test using Skyramp's deterministic test generation platform.

Load tests evaluate your application's performance, scalability, and stability under various traffic conditions. They simulate multiple concurrent users, measure response times, identify performance bottlenecks, and ensure your system can handle expected traffic volumes.

***IMPORTANT***
- At any given time you can provide duration of the test or test execution count
- IF THE USER DOES NOT PROVIDE LOAD PARAMETERS, THEN USE DEFAULT VALUES FOR LOAD TESTS:
  - loadDuration: "5" (5 seconds)
  - loadNumThreads: "1" (1 thread)
  - Other load parameters should remain empty unless explicitly specified by the user

**IMPORTANT: If an apiSchema parameter (OpenAPI/Swagger file path or URL) is provided, DO NOT attempt to read or analyze the file contents. These files can be very large. Simply pass the path/URL to the tool - the backend will handle reading and processing the schema file.**

**CRITICAL - When using trace parameter:**
If \`trace\` parameter is provided (path to a trace file), DO NOT pass \`apiSchema\` or \`endpointURL\` parameters. The trace file already contains all necessary endpoint and schema information. Passing both will cause test generation to fail.`,
        inputSchema: loadTestSchema,
        _meta: {
            keywords: ["load test", "performance test"],
        },
    }, async (params) => {
        const service = new LoadTestService();
        const result = await service.generateTest(params);
        AnalyticsService.pushTestGenerationToolEvent(TOOL_NAME, result, params).catch(() => {
            // Silently ignore analytics errors
        });
        return result;
    });
}
