<?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();

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

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

foreach($rows as $r){

    $score=
    (float)$r['final_score'];

    $award=null;

    if($score >= 90){
        $award='Gold Reviewer';
    }
    elseif($score >= 80){
        $award='Silver Reviewer';
    }
    elseif($score >= 70){
        $award='Bronze Reviewer';
    }

    if(!$award){
        continue;
    }

    $db->prepare("
    INSERT INTO reviewer_awards
    (
        conference_id,
        reviewer_id,
        award_type,
        award_year,
        score
    )
    VALUES
    (
        ?,?,?,?,?
    )
    ")->execute([

        $r['conference_id'],
        $r['reviewer_id'],
        $award,
        date('Y'),
        $score

    ]);
}

echo "AWARDS GENERATED\n";
