<?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 "STRATEGIC OPTIMIZATION\n";

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

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

foreach($rows as $r){

    if($r['overall_health_score'] < 60){

        $db->prepare("
        INSERT INTO
        strategic_conference_optimization
        (
            conference_id,
            optimization_type,
            priority_level,
            recommendation_text,
            optimization_score
        )
        VALUES
        (
            ?,?,?,?,?
        )
        ")->execute([
            $r['conference_id'],
            'reviewer_pool_expansion',
            'High',
            'Expand reviewer pool by 20% and rebalance assignments',
            100 - $r['overall_health_score']
        ]);

    }

    if($r['track_health_score'] < 20){

        $db->prepare("
        INSERT INTO
        strategic_conference_optimization
        (
            conference_id,
            optimization_type,
            priority_level,
            recommendation_text,
            optimization_score
        )
        VALUES
        (
            ?,?,?,?,?
        )
        ")->execute([
            $r['conference_id'],
            'track_restructure',
            'Medium',
            'Review track distribution and rebalance workload',
            100 - $r['track_health_score']
        ]);

    }

}

echo "DONE\n";
