<?php

namespace App\Services;

use App\Core\Database;

class PlatformOperatingSystemService
{

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

$db=
Database::getInstance();

$out=[];

$queries=[

'events'=>

"

SELECT COUNT(*)

FROM platform_event_bus

WHERE conference_id=?

",

'notifications'=>

"

SELECT COUNT(*)

FROM platform_notifications

",

'deployments'=>

"

SELECT COUNT(*)

FROM conference_home_deployments

WHERE conference_id=?

",

'incidents'=>

"

SELECT COUNT(*)

FROM conference_home_incidents

WHERE conference_id=?

"

];

$stmt=
$db
->prepare(
$queries[
'events'
]
);

$stmt
->execute([

$conferenceId

]);

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

$stmt=
$db
->prepare(
$queries[
'notifications'
]
);

$stmt
->execute();

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

foreach(
[
'deployments',
'incidents'
]
as $k
){

$s=
$db
->prepare(
$queries[
$k
]
);

$s
->execute([

$conferenceId

]);

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

}

$out[
'status'
]=

$out[
'incidents'
]
===0

?

'stable'

:

'attention';

return
$out;

}

}
