<?php

namespace App\Services;

use App\Core\Database;

class PlatformCognitiveService
{

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

$db=
Database::getInstance();

$out=[];

$queries=[

'memory'=>

"

SELECT COUNT(*)

FROM platform_memory

WHERE conference_id=?

",

'agents'=>

"

SELECT COUNT(*)

FROM conference_home_agent_plans

WHERE conference_id=?

",

'brain'=>

"

SELECT COUNT(*)

FROM conference_home_brain

WHERE conference_id=?

",

'cognition'=>

"

SELECT COUNT(*)

FROM platform_cognition

WHERE conference_id=?

"

];

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

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

$stmt
->execute([

$conferenceId

]);

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

}

$out[
'intelligence'
]=

min(

100,

55+

$out[
'memory'
]

+

(
$out[
'agents'
]*2
)

+

(
$out[
'brain'
]*3
)

);

$insights=[];

if(
$out[
'memory'
]<5
){

$insights[]=
'Increase remembered decisions';

}

if(
$out[
'agents'
]<2
){

$insights[]=
'Generate execution plans';

}

if(
$out[
'brain'
]<3
){

$insights[]=
'Expand decision analysis';

}

return [

'metrics'=>$out,

'intelligence'=>

$out[
'intelligence'
],

'insights'=>

$insights,

'state'=>

$out[
'intelligence'
]>=85

?

'cognitive'

:

'learning'

];

}

}
