<?php

namespace App\Services;

use App\Core\Database;

class PlatformNeuralMeshService
{

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

$db=
Database::getInstance();

$out=[];

$queries=[

'mesh'=>

"

SELECT COUNT(*)

FROM platform_neural_mesh

WHERE conference_id=?

",

'agents'=>

"

SELECT COUNT(*)

FROM conference_home_agents

WHERE is_enabled=1

",

'coordination'=>

"

SELECT COUNT(*)

FROM platform_agent_coordination

WHERE conference_id=?

",

'cognition'=>

"

SELECT COUNT(*)

FROM platform_cognition

WHERE conference_id=?

"

];

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

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

if(
$k==='agents'
){

$stmt
->execute();

}
else{

$stmt
->execute([

$conferenceId

]);

}

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

}

$out[
'mesh_score'
]=

min(

100,

50+

(
$out[
'agents'
]*3
)

+

(
$out[
'coordination'
]*2
)

+

$out[
'cognition'
]

);

$out[
'state'
]=

$out[
'mesh_score'
]>=85

?

'synchronized'

:

'forming';

return
$out;

}

}
