<?php

namespace App\Services;

use App\Core\Database;

class PlatformConsciousService
{

public static function dashboard(
int $conferenceId
): array
{

$db=
Database::getInstance();

$out=[];

$queries=[

'goals'=>

"

SELECT COUNT(*)

FROM platform_goals

WHERE conference_id=?

",

'completed'=>

"

SELECT COUNT(*)

FROM platform_goals

WHERE conference_id=?

AND goal_current>=goal_target

",

'cycles'=>

"

SELECT COUNT(*)

FROM platform_optimization_cycles

WHERE conference_id=?

",

'memory'=>

"

SELECT COUNT(*)

FROM platform_memory

WHERE conference_id=?

"

];

foreach(
$queries
as $k=>$sql
){

$stmt=
$db
->prepare(
$sql
);

$stmt
->execute([

$conferenceId

]);

$out[
$k
]=
(int)
$stmt
->fetchColumn();

}

$out[
'awareness'
]=

$out[
'goals'
]

?

min(

100,

round(

(
$out[
'completed'
]
/
max(
1,
$out[
'goals'
]
)

)
*
100

)

+

$out[
'cycles'
]

)

:

0;

$advice=[];

if(
$out[
'goals'
]<3
){
$advice[]=
'Define measurable goals';
}

if(
$out[
'cycles'
]<2
){
$advice[]=
'Run optimization reviews';
}

if(
$out[
'memory'
]<5
){
$advice[]=
'Capture operational context';
}

return [

'metrics'=>$out,

'awareness'=>
$out[
'awareness'
],

'advice'=>
$advice,

'state'=>

$out[
'awareness'
]>=80

?

'aware'

:

'learning'

];

}

}
