<?php

namespace App\Services;

use App\Core\Database;

class PlatformLegacyPrimeService
{

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

$db=
Database::getInstance();

$queries=[

'engine'=>
"
SELECT COUNT(*)
FROM platform_regeneration_engine
WHERE org_id=?
",

'resilient'=>
"
SELECT COUNT(*)
FROM platform_regeneration_engine
WHERE org_id=?
AND regeneration_score>=resilience_score
",

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

'renewed'=>
"
SELECT COUNT(*)
FROM platform_renewal_observatory
WHERE conference_id=?
AND renewal_score>=80
"

];

$out=[];

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

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

$stmt->execute([

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

]);

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

}

$out[
'renewal'
]=

$out[
'observatory'
]

?

min(

100,

round(

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

)
*
100

)

+

(
$out[
'resilient'
]
*2
)

)

:

0;

$out[
'state'
]=

$out[
'renewal'
]>=85

?

'renewed'

:

'regenerating';

return $out;

}

}
