<?php

namespace App\Services;

use App\Core\Database;

class PlatformHorizonPrimeService
{

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

$db=
Database::getInstance();

$queries=[

'controls'=>
"
SELECT COUNT(*)
FROM platform_meta_control
WHERE org_id=?
",

'stable'=>
"
SELECT COUNT(*)
FROM platform_meta_control
WHERE org_id=?
AND control_score>=stability_score
",

'signals'=>
"
SELECT COUNT(*)
FROM platform_strategic_observatory
WHERE conference_id=?
",

'strong'=>
"
SELECT COUNT(*)
FROM platform_strategic_observatory
WHERE conference_id=?
AND signal_score>=80
"

];

$out=[];

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

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

$stmt->execute([

in_array(
$k,
[
'signals',
'strong'
]
)
?
$conferenceId
:
$orgId

]);

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

}

$out[
'strategy'
]=

$out[
'signals'
]

?

min(

100,

round(

(
$out[
'strong'
]
/
max(
1,
$out[
'signals'
]
)

)
*
100

)

+

(
$out[
'stable'
]
*2
)

)

:

0;

$out[
'state'
]=

$out[
'strategy'
]>=85

?

'strategic'

:

'monitoring';

return $out;

}

}
