<?php

declare(strict_types=1);

/**
 * Smoke test: lead-in quality blocks present in generator and combined reviewer prompts.
 */

$failures = 0;

function assertContains(string $haystack, string $needle, string $label): void
{
    global $failures;
    if (str_contains($haystack, $needle)) {
        echo "OK: {$label}\n";
        return;
    }
    echo "FAIL: {$label} (missing: {$needle})\n";
    $failures++;
}

$generator = file_get_contents(dirname(__DIR__) . '/prompts/generator_prompt.php');
$reviewer = file_get_contents(dirname(__DIR__) . '/prompts/sba_combined_tutor_reviewer_prompt.php');

assertContains($generator, 'What is the most likely diagnosis?', 'generator: diagnosis lead-in');
assertContains($generator, 'What is the most appropriate **initial** investigation?', 'generator: investigation lead-in');
assertContains($generator, 'What is the best interpretation of these findings?', 'generator: interpretation lead-in');
assertContains($generator, 'What treatment should be given first?', 'generator: emergency lead-in');
assertContains($generator, 'assessment tool', 'generator: risk score / assessment tool');
assertContains($generator, 'both cover tests', 'generator: cover tests');
assertContains($generator, 'Which of the following is correct', 'generator: avoid vague which');

assertContains($reviewer, 'Lead-in quality (mandatory', 'reviewer: lead-in section');
assertContains($reviewer, '"field": "lead_in"', 'reviewer: lead_in suggested edit');
assertContains($reviewer, 'Glasgow–Blatchford', 'reviewer: risk score example');
assertContains($reviewer, 'What is the most likely diagnosis?', 'reviewer: diagnosis pattern');
assertContains($reviewer, 'assessment tool is used to estimate', 'reviewer: assessment tool suggestion');

echo PHP_EOL;
if ($failures > 0) {
    echo "{$failures} test(s) failed.\n";
    exit(1);
}
echo "All lead-in prompt block tests passed.\n";
