<?php

require dirname(__DIR__) . '/prompts/sba_pe_emergency_concepts.php';
require dirname(__DIR__) . '/validators/style_validator.php';

function assertHasCode(array $warnings, string $code, string $label): void
{
    foreach ($warnings as $w) {
        if (($w['code'] ?? '') === $code) {
            echo 'OK: ' . $label . PHP_EOL;

            return;
        }
    }
    echo 'FAIL: ' . $label . ' (missing ' . $code . ')' . PHP_EOL;
    exit(1);
}

$demo = [
    '_current_skill' => 'Investigation',
    '_condition_name' => 'Pulmonary embolism',
    'stem' => 'A 26 year old man presents with pleuritic chest pain. He takes oral contraceptives.',
];
assertHasCode(
    sbaStyleWarningsStemDemographicConsistency($demo),
    'stem.demographic_sex_risk_factor_mismatch',
    'man with oral contraceptives warns'
);

$ctpa = [
    '_current_skill' => 'Interpretation',
    '_condition_name' => 'Pulmonary embolism',
    'stem' => 'CT pulmonary angiogram shows a filling defect in the right pulmonary artery.',
    'correct_answer' => 'High probability of pulmonary embolism',
    'option_a' => 'High probability of pulmonary embolism',
    'option_b' => 'Pulmonary embolism',
];
assertHasCode(
    sbaStyleWarningsInterpretationDefinitiveImagingResult($ctpa, $ctpa['stem'], $ctpa['correct_answer']),
    'interpretation.pe_definitive_ctpa_probability_key',
    'definitive CTPA with probability key warns'
);

$mgmt = [
    '_current_skill' => 'Management',
    '_condition_name' => 'Pulmonary embolism',
    'option_a' => 'Start low-molecular-weight heparin',
    'option_b' => 'Initiate anticoagulation therapy',
    'option_c' => 'Arrange outpatient review',
    'option_d' => 'Give oxygen therapy',
    'option_e' => 'Request CT pulmonary angiogram',
];
assertHasCode(
    sbaStyleWarningsFormSkillStemOptions($mgmt),
    'skill_alignment.management_anticoagulation_class_overlap',
    'LMWH plus initiate anticoagulation warns'
);

echo PHP_EOL . 'All mixed-skill PE rule tests passed.' . PHP_EOL;
