<?php

declare(strict_types=1);

$options = getopt('', ['target::']);
require __DIR__ . DIRECTORY_SEPARATOR . 'diar6b4-r2-lib.php';

try {
    $root = diarR2Bootstrap($options);
    $result = diarR2CleanupQaCases($root);
    echo 'DIAR_6B_4_R2_QA_CLEANUP|PASS|CASES=' . $result['cases']
        . '|CHILD_ROWS=' . $result['child_rows']
        . '|REMAINING_QA_CASES=0|REAL_CASES_TOUCHED=0|SOURCE_MM_WRITES=NONE|DB_LINK=NONE' . PHP_EOL;
    exit(0);
} catch (Throwable $error) {
    fwrite(STDERR, 'DIAR_6B_4_R2_QA_CLEANUP|FAIL|ERROR=' . $error->getMessage() . PHP_EOL);
    exit(24);
}
