<?php

namespace App\Services;

use App\Core\Database;

class HomepageMissionControlService
{

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

$db=
Database::getInstance();

$out=[];

$map=[

'sections'=>

"

SELECT COUNT(*)
FROM conference_home_sections
WHERE conference_id=?

",

'blocks'=>

"

SELECT COUNT(*)
FROM conference_homepage_blocks
WHERE conference_id=?

",

'branches'=>

"

SELECT COUNT(*)
FROM conference_home_branches
WHERE conference_id=?

",

'deployments'=>

"

SELECT COUNT(*)
FROM conference_home_deployments
WHERE conference_id=?

",

'notifications'=>

"

SELECT COUNT(*)
FROM conference_home_notifications
WHERE conference_id=?

"

];

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

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

$stmt
->execute([

$conferenceId

]);

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

}

$out[
'health'
]=

min(

100,

40+

$out[
'sections'
]

+

$out[
'blocks'
]

+

(
$out[
'deployments'
]
*5

)

);

return
$out;

}

}
