<?php

define(
'BASE_PATH',
realpath(__DIR__.'/../..')
);

require_once BASE_PATH.'/config/autoload.php';
require_once BASE_PATH.'/config/bootstrap.php';

$db=\App\Core\Database::getInstance();

echo "SELF HEALING\n";

$db->exec(
"TRUNCATE TABLE self_healing_actions"
);

$rows=
$db->query("
SELECT *
FROM predictive_conference_intelligence
")->fetchAll(PDO::FETCH_ASSOC);

foreach($rows as $r){

    $severity='Medium';

    $action='';

    if(
        $r['prediction_type']
        ==
        'reviewer_failure_risk'
    ){

        $severity='Critical';

        $action=
        'Assign replacement reviewer and issue escalation';
    }

    if(
        $r['prediction_type']
        ==
        'conference_health_decline'
    ){

        $severity='High';

        $action=
        'Expand reviewer pool and increase assignment coverage';
    }

    $db->prepare("
    INSERT INTO self_healing_actions
    (
        conference_id,
        healing_type,
        severity,
        action_text
    )
    VALUES
    (
        ?,?,?,?
    )
    ")->execute([
        $r['conference_id'],
        $r['prediction_type'],
        $severity,
        $action
    ]);

}

echo "DONE\n";
