<?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 "AUTONOMOUS PLANNING\n";

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

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

foreach($rows as $r){

    $cid=(int)$r['conference_id'];

    $gap=(float)$r['improvement_gap'];

    $actions=[
        [1,'Recruit additional reviewers','Reviewer Pool',round($gap*0.30,2)],
        [2,'Rebalance reviewer assignments','Assignment Quality',round($gap*0.25,2)],
        [3,'Improve track distribution','Track Health',round($gap*0.25,2)],
        [4,'Reduce overdue reviews','Workflow Efficiency',round($gap*0.20,2)],
    ];

    foreach($actions as $a){

        $db->prepare("
        INSERT INTO autonomous_plans
        (
            conference_id,
            plan_horizon,
            week_no,
            action_text,
            target_metric,
            expected_gain
        )
        VALUES
        (
            ?,?,?,?,?,?
        )
        ")->execute([
            $cid,
            '30-Day',
            $a[0],
            $a[1],
            $a[2],
            $a[3]
        ]);

    }
}

echo "DONE\n";
