<?php

namespace App\Services;

use App\Core\Database;

class PlatformObservatoryPrimeService
{

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

$db=
Database::getInstance();

$queries=[

'observatories'=>
"
SELECT COUNT(*)
FROM platform_observatory_prime
WHERE org_id=?
",

'aware'=>
"
SELECT COUNT(*)
FROM platform_observatory_prime
WHERE org_id=?
AND awareness_score>=80
",

'insights'=>
"
SELECT COUNT(*)
FROM platform_insight_network
WHERE conference_id=?
",

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

];

$out=[];

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

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

$stmt->execute([

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

]);

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

}

$out[
'awareness'
]=

$out[
'insights'
]

?

min(

100,

round(

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

)
*
100

)

+

(
$out[
'aware'
]
*2
)

)

:

0;

$out[
'state'
]=

$out[
'awareness'
]>=85

?

'aware'

:

'observing';

return $out;

}

}
