// tools/generate-tests/adapters/contract-testing-adapter.ts
// SPEC-018: Adapter connecting contract/mock generators to generate_tests tool output
import { generateContractSpec, getContractFilePath, buildSampleEndpoints, } from '../../../engine/test-generators/contract-test-generator.js';
import { generateMockDefinitions, generateMockServerContent, detectMockTool, getMockFileExtension, } from '../../../engine/test-generators/mock-generator.js';
// === Contract test file generation ===
/**
 * Generate contract spec file (OpenAPI/Pact/GraphQL/tRPC) for a spec.
 * Returns a TestFile ready to be added to the tool output.
 */
export function buildContractTestFile(specTitle, specSlug, knowledge, autoGenerate) {
    const contractSpec = generateContractSpec(specTitle, knowledge);
    const filePath = getContractFilePath(specSlug, contractSpec.format);
    return {
        path: filePath,
        framework: `contract-${contractSpec.format}`,
        content: contractSpec.content,
        ready: autoGenerate,
    };
}
// === Mock file generation ===
/**
 * Generate mock server file (MSW/json-server/WireMock) for a spec.
 * Returns a TestFile ready to be added to the tool output.
 */
export function buildMockServerFile(specTitle, specSlug, knowledge, autoGenerate) {
    const endpoints = buildSampleEndpoints(specTitle);
    const mocks = generateMockDefinitions(endpoints, specTitle);
    const tool = detectMockTool(knowledge.stack);
    const ext = getMockFileExtension(tool);
    const content = generateMockServerContent(mocks, specTitle, tool);
    return {
        path: `mocks/${specSlug}.mock.${ext}`,
        framework: `mock-${tool}`,
        content,
        ready: autoGenerate,
    };
}
// === Summary lines for output ===
/**
 * Build human-readable summary lines for the contract + mock section.
 */
export function buildContractMockSummaryLines(specTitle, knowledge) {
    const contractSpec = generateContractSpec(specTitle, knowledge);
    const endpoints = buildSampleEndpoints(specTitle);
    const tool = detectMockTool(knowledge.stack);
    const lines = [
        '### Contract Testing',
        '',
        `**Format:** ${contractSpec.format} (auto-detected from project stack)`,
        `**Endpoints:** ${endpoints.length} endpoints scaffolded`,
        '',
        '| Method | Path | Status Codes |',
        '|--------|------|--------------|',
        ...endpoints.map((ep) => `| ${ep.method} | \`${ep.path}\` | ${ep.statusCodes.join(', ')} |`),
        '',
        '### Mock Server',
        '',
        `**Tool:** ${tool} (auto-detected)`,
        `**Mocks:** ${endpoints.length} endpoint mocks generated from explicit contracts`,
        ...(endpoints.length === 0
            ? [
                '> No endpoints were provided; Planu did not fabricate API paths, status codes, or mock payloads.',
            ]
            : []),
        '',
        ...(endpoints.length > 0
            ? ['> Frontend developers can use these mocks to work independently of the backend.']
            : []),
        '',
    ];
    return lines;
}
//# sourceMappingURL=contract-testing-adapter.js.map