<?php

namespace App\Services;

use App\Core\Database;

class PlatformCentralNervousService
{

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

$db=
Database::getInstance();

$out=[];

$queries=[

'signals'=>

"

SELECT COUNT(*)

FROM platform_signals

WHERE conference_id=?

",

'bus'=>

"

SELECT COUNT(*)

FROM platform_intelligence_bus

WHERE conference_id=?

",

'events'=>

"

SELECT COUNT(*)

FROM platform_event_bus

WHERE conference_id=?

",

'domains'=>

"

SELECT COUNT(*)

FROM platform_domains

WHERE org_id=?

"

];

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

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

if(
$k==='domains'
){

$stmt
->execute([

$orgId

]);

}
else{

$stmt
->execute([

$conferenceId

]);

}

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

}

$out[
'awareness'
]=

min(

100,

60+

(
$out[
'signals'
]*2
)

+

(
$out[
'bus'
]*3
)

);

$out[
'state'
]=

$out[
'awareness'
]>=85

?

'observing'

:

'collecting';

return
$out;

}

}
