<?php

namespace App\Services;

use App\Core\Database;

class HomepageControlTowerService
{

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

$db=
Database::getInstance();

$out=[];

$queries=[

'incidents'=>

"

SELECT COUNT(*)

FROM conference_home_incidents

WHERE conference_id=?

AND incident_state='open'

",

'maintenance'=>

"

SELECT COUNT(*)

FROM conference_home_maintenance

WHERE conference_id=?

",

'deployments'=>

"

SELECT COUNT(*)

FROM conference_home_deployments

WHERE conference_id=?

",

'health'=>

"

SELECT COUNT(*)

FROM conference_home_services

WHERE conference_id=?

AND service_state='healthy'

"

];

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

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

$stmt
->execute([

$conferenceId

]);

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

}

$out[
'status'
]=

$out[
'incidents'
]

?

'attention'

:

'normal';

return
$out;

}

public static function maintain(
int $conferenceId
): bool
{

$db=
Database::getInstance();

return
$db
->prepare("

INSERT INTO
conference_home_maintenance(

conference_id,

action_name,

action_result

)

VALUES(

?,

'maintenance_check',

'ok'

)

")

->execute([

$conferenceId

]);

}

}
