<?php

namespace App\Services;

use App\Core\Database;

class PlatformMetaService
{

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

$db=
Database::getInstance();

$out=[];

$queries=[

'reflections'=>

"

SELECT COUNT(*)

FROM platform_meta_reflections

WHERE conference_id=?

",

'cycles'=>

"

SELECT COUNT(*)

FROM platform_evolution_cycles

WHERE conference_id=?

",

'memory'=>

"

SELECT COUNT(*)

FROM platform_memory

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[
'maturity'
]=

min(

100,

50+

$out[
'reflections'
]

+

(
$out[
'cycles'
]*3
)

+

(
$out[
'cognition'
]*2
)

);

$signals=[];

if(
$out[
'reflections'
]<3
){
$signals[]=
'Capture platform observations';
}

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

if(
$out[
'memory'
]<10
){
$signals[]=
'Increase retained decisions';
}

return [

'metrics'=>$out,

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

'signals'=>
$signals,

'state'=>

$out[
'maturity'
]>=85

?

'evolving'

:

'observing'

];

}

}
