<?php
// Master test script
$tests = [
    'Short Prefix' => 'short_prefix',
    'Short Length' => 'short_length',
    'Valid Inputs' => 'valid_inputs'
];

foreach ($tests as $name => $mode) {
    $cmd = "C:\\xampp\\php\\php.exe scratch/test_settings_validation_runner.php $mode";
    $output = shell_exec($cmd);
    
    // Find JSON portion if any
    $json_start = strpos($output, '{');
    $data = null;
    if ($json_start !== false) {
        $json_str = substr($output, $json_start);
        $data = json_decode($json_str, true);
    }
    
    $passed = false;
    $reason = "Output: " . trim($output);
    
    if (strpos($output, 'PASSED') !== false) {
        $passed = true;
    } elseif ($data) {
        if ($mode === 'short_prefix') {
            if (!$data['success'] && strpos($data['message'], "prefix must be exactly 4 or 5 characters") !== false) {
                $passed = true;
            } else {
                $reason = "Expected prefix error, got success: " . ($data['success'] ? 'true' : 'false') . ", message: " . $data['message'];
            }
        } elseif ($mode === 'short_length') {
            if (!$data['success'] && strpos($data['message'], "length must be between 15 and 30 characters") !== false) {
                $passed = true;
            } else {
                $reason = "Expected length error, got success: " . ($data['success'] ? 'true' : 'false') . ", message: " . $data['message'];
            }
        } elseif ($mode === 'valid_inputs') {
            if ($data['success']) {
                $passed = true;
            } else {
                $reason = "Expected success, got failure: " . $data['message'];
            }
        }
    }
    
    echo "$name: " . ($passed ? "PASSED" : "FAILED - " . $reason) . "\n";
}
