// engine/test-spec-generator/criterion-parser.ts — Extract Given/When/Then from criteria text
export function suggestTestData(criterion) {
    const lower = criterion.toLowerCase();
    if (lower.includes('api') || lower.includes('endpoint') || lower.includes('url')) {
        return 'endpoint: "https://api.example.com/v1/resource", method: "POST"';
    }
    if (lower.includes('user') || lower.includes('usuario') || lower.includes('usuário')) {
        return 'user: { id: "usr-123", email: "test@example.com", role: "admin" }';
    }
    if (lower.includes('email')) {
        return 'email: "user@example.com", subject: "Test subject", body: "Test body"';
    }
    if (lower.includes('file') || lower.includes('arquivo') || lower.includes('fichero')) {
        return 'file: { path: "/tmp/test.json", size: 1024, mimeType: "application/json" }';
    }
    if (lower.includes('database') || lower.includes('db') || lower.includes('banco')) {
        return 'db: { host: "localhost", port: 5432, name: "test_db" }';
    }
    if (lower.includes('token') || lower.includes('auth') || lower.includes('jwt')) {
        return 'token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.test.signature"';
    }
    if (lower.includes('config')) {
        return 'config: { enabled: true, timeout: 5000, retries: 3 }';
    }
    if (lower.includes('spec') || lower.includes('criteria')) {
        return 'specId: "SPEC-001", title: "Test feature", criteria: ["criterion 1", "criterion 2"]';
    }
    return undefined;
}
export function extractGiven(criterion, labels) {
    const lower = criterion.toLowerCase();
    // If criterion mentions a precondition pattern ("given X", "when X exists")
    if (lower.startsWith('given ') || lower.startsWith('dado ') || lower.startsWith('dado que ')) {
        const match = /^(?:given|dado(?: que)?)\s+(.+?)(?:\s+when\s+|\s+,\s+|\s+then\s+|$)/i.exec(criterion);
        if (match?.[1]) {
            return match[1];
        }
    }
    return labels.givenSetup;
}
export function extractWhen(criterion, labels) {
    const lower = criterion.toLowerCase();
    // Pattern: "X generates Y" → when: "X is executed"
    const generatesMatch = /^(.+?)\s+generates?\s+/i.exec(criterion);
    if (generatesMatch?.[1]) {
        return labels.locale === 'es'
            ? `se ejecuta "${generatesMatch[1].trim()}"`
            : labels.locale === 'pt'
                ? `"${generatesMatch[1].trim()}" é executado`
                : `"${generatesMatch[1].trim()}" is executed`;
    }
    // Pattern: "X creates Y"
    const createsMatch = /^(.+?)\s+creates?\s+/i.exec(criterion);
    if (createsMatch?.[1]) {
        return labels.locale === 'es'
            ? `se ejecuta "${createsMatch[1].trim()}"`
            : labels.locale === 'pt'
                ? `"${createsMatch[1].trim()}" é executado`
                : `"${createsMatch[1].trim()}" is executed`;
    }
    // Pattern: "X returns Y"
    const returnsMatch = /^(.+?)\s+returns?\s+/i.exec(criterion);
    if (returnsMatch?.[1]) {
        const subject = returnsMatch[1].trim();
        return lower.includes(subject.toLowerCase())
            ? `${subject} is called`
            : /* v8 ignore next 1 */ labels.whenExecuted;
    }
    return labels.whenExecuted;
}
export function extractThen(criterion, labels) {
    const lower = criterion.toLowerCase();
    // "X generates Y" → then: "Y is generated correctly"
    const generatesMatch = /generates?\s+(.+)/i.exec(criterion);
    if (generatesMatch?.[1]) {
        const target = generatesMatch[1].trim().replace(/\.$/, '');
        return `${target} ${labels.thenCorrect}`;
    }
    // "X creates Y"
    const createsMatch = /creates?\s+(.+)/i.exec(criterion);
    if (createsMatch?.[1]) {
        const target = createsMatch[1].trim().replace(/\.$/, '');
        return `${target} ${labels.thenCorrect}`;
    }
    // "X returns Y"
    const returnsMatch = /returns?\s+(.+)/i.exec(criterion);
    if (returnsMatch?.[1]) {
        const target = returnsMatch[1].trim().replace(/\.$/, '');
        return `${target} ${labels.thenCorrect}`;
    }
    // Fallback: use the criterion itself as the expected result
    return lower.startsWith('the ') || lower.startsWith('el ') || lower.startsWith('o ')
        ? criterion.replace(/\.$/, '')
        : criterion.replace(/\.$/, '') + ' ' + labels.thenCorrect;
}
//# sourceMappingURL=criterion-parser.js.map