<?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 "REVIEWER TALENT MANAGEMENT\n";

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

$rows=
$db->query("
SELECT
reviewer_id,
conference_id,
final_assignment_score
FROM reviewer_assignment_scores
")->fetchAll(PDO::FETCH_ASSOC);

foreach($rows as $r){

    $score=
    round(
        (float)$r['final_assignment_score'],
        2
    );

    $talent='Developing';
    $risk='Medium';

    if($score>=75){
        $talent='Elite';
        $risk='Low';
    }
    elseif($score>=50){
        $talent='Advanced';
        $risk='Low';
    }
    elseif($score>=25){
        $talent='Growing';
        $risk='Medium';
    }
    else{
        $talent='At Risk';
        $risk='High';
    }

    $leadership=
    round(
        min(100,$score*1.10),
        2
    );

    $recommendation=
    'Continue reviewer development';

    if($talent==='Elite'){
        $recommendation=
        'Consider Track Chair or Senior Reviewer role';
    }

    $db->prepare("
    INSERT INTO reviewer_talent_management
    (
        reviewer_id,
        conference_id,
        talent_score,
        talent_level,
        leadership_potential,
        risk_level,
        recommendation_text
    )
    VALUES
    (
        ?,?,?,?,?,?,?
    )
    ")->execute([
        $r['reviewer_id'],
        $r['conference_id'],
        $score,
        $talent,
        $leadership,
        $risk,
        $recommendation
    ]);

}

echo "DONE\n";
