<?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 ACADEMY PROGRAMS\n";

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

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

foreach($rows as $r){

    $program='General Academy';
    $level='Foundation';

    if(
        $r['succession_role']
        ==
        'Conference Chair Successor'
    ){

        $program='Leadership Academy';
        $level='Executive';

    }
    elseif(
        $r['succession_role']
        ==
        'Track Chair Successor'
    ){

        $program='Leadership Academy';
        $level='Track Leadership';

    }
    elseif(
        $r['succession_role']
        ==
        'Reviewer Successor'
    ){

        $program='Excellence Academy';
        $level='Advanced Reviewer';

    }
    elseif(
        $r['succession_role']
        ==
        'Recovery Program'
    ){

        $program='Recovery Academy';
        $level='Recovery Track';

    }

    $recommendation=
    'Continue reviewer development';

    if(
        $program
        ==
        'Leadership Academy'
    ){
        $recommendation=
        'Prepare for future leadership responsibilities';
    }

    if(
        $program
        ==
        'Excellence Academy'
    ){
        $recommendation=
        'Enhance reviewer quality and mentoring skills';
    }

    if(
        $program
        ==
        'Recovery Academy'
    ){
        $recommendation=
        'Complete recovery and mentoring activities';
    }

    $db->prepare("
    INSERT INTO reviewer_academy_programs
    (
        reviewer_id,
        conference_id,
        academy_program,
        academy_level,
        academy_score,
        recommendation_text
    )
    VALUES
    (
        ?,?,?,?,?,?
    )
    ")->execute([
        $r['reviewer_id'],
        $r['conference_id'],
        $program,
        $level,
        $r['readiness_score'],
        $recommendation
    ]);

}

echo "DONE\n";
