<?php

namespace App\Services;

use App\Core\Database;

class PlatformGenesisPrimeService
{

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

$db=
Database::getInstance();

$queries=[

'kernel'=>
"
SELECT COUNT(*)
FROM platform_rebirth_kernel
WHERE org_id=?
",

'ready'=>
"
SELECT COUNT(*)
FROM platform_rebirth_kernel
WHERE org_id=?
AND evolution_score>=continuity_score
",

'observatory'=>
"
SELECT COUNT(*)
FROM platform_evolution_observatory
WHERE conference_id=?
",

'evolved'=>
"
SELECT COUNT(*)
FROM platform_evolution_observatory
WHERE conference_id=?
AND evolution_score>=80
"

];

$out=[];

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

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

$stmt->execute([

in_array(
$k,
[
'observatory',
'evolved'
]
)
?
$conferenceId
:
$orgId

]);

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

}

$out[
'evolution'
]=

$out[
'observatory'
]

?

min(

100,

round(

(
$out[
'evolved'
]
/
max(
1,
$out[
'observatory'
]
)

)
*
100

)

+

(
$out[
'ready'
]
*2
)

)

:

0;

$out[
'state'
]=

$out[
'evolution'
]>=85

?

'evolved'

:

'renewing';

return $out;

}

}
