<?php

namespace App\Services;

use App\Core\Database;

class PlatformEternalService
{

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

$db=
Database::getInstance();

$queries=[

'memory'=>
"
SELECT COUNT(*)
FROM platform_memory_mesh
WHERE org_id=?
",

'retained'=>
"
SELECT COUNT(*)
FROM platform_memory_mesh
WHERE org_id=?
AND retention_score>=continuity_score
",

'knowledge'=>
"
SELECT COUNT(*)
FROM platform_knowledge_continuum
WHERE conference_id=?
",

'connected'=>
"
SELECT COUNT(*)
FROM platform_knowledge_continuum
WHERE conference_id=?
AND knowledge_score>=80
"

];

$out=[];

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

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

$stmt->execute([

in_array(
$k,
[
'knowledge',
'connected'
]
)
?
$conferenceId
:
$orgId

]);

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

}

$out[
'continuum'
]=

$out[
'knowledge'
]

?

min(

100,

round(

(
$out[
'connected'
]
/
max(
1,
$out[
'knowledge'
]
)

)
*
100

)

+

(
$out[
'retained'
]
*2
)

)

:

0;

$out[
'state'
]=

$out[
'continuum'
]>=85

?

'eternal'

:

'learning';

return $out;

}

}
